1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// +build ignore
#import <Foundation/Foundation.h>
#import <XCTest/XCTest.h>
#import "benchmark/Benchmark.h"
@interface AnI : NSObject <BenchmarkI> {
}
@end
@implementation AnI
- (void)f {
}
@end
@interface Benchmarks : NSObject <BenchmarkBenchmarks> {
}
@end
@implementation Benchmarks
- (void)manyargs:(long)p0 p1:(long)p1 p2:(long)p2 p3:(long)p3 p4:(long)p4 p5:(long)p5 p6:(long)p6 p7:(long)p7 p8:(long)p8 p9:(long)p9 {
}
- (id<BenchmarkI>)newI {
return [[AnI alloc] init];
}
- (void)noargs {
}
- (void)onearg:(long)p0 {
}
- (long)oneret {
return 0;
}
- (void)ref:(id<BenchmarkI>)p0 {
}
- (void)slice:(NSData*)p0 {
}
- (void)string:(NSString*)p0 {
}
- (NSString*)stringRetLong {
return BenchmarkLongString;
}
- (NSString*)stringRetShort {
return BenchmarkShortString;
}
- (void (^)(void))lookupBenchmark:(NSString *)name {
if ([name isEqualToString:@"Empty"]) {
return ^() {
};
} else if ([name isEqualToString:@"Noargs"]) {
return ^() {
BenchmarkNoargs();
};
} else if ([name isEqualToString:@"Onearg"]) {
return ^() {
BenchmarkOnearg(0);
};
} else if ([name isEqualToString:@"Manyargs"]) {
return ^() {
BenchmarkManyargs(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
};
} else if ([name isEqualToString:@"Oneret"]) {
return ^() {
BenchmarkOneret();
};
} else if ([name isEqualToString:@"Refforeign"]) {
id<BenchmarkI> objcRef = [[AnI alloc] init];
return ^() {
BenchmarkRef(objcRef);
};
} else if ([name isEqualToString:@"Refgo"]) {
id<BenchmarkI> goRef = BenchmarkNewI();
return ^() {
BenchmarkRef(goRef);
};
} else if ([name isEqualToString:@"StringShort"]) {
return ^() {
BenchmarkString(BenchmarkShortString);
};
} else if ([name isEqualToString:@"StringLong"]) {
return ^() {
BenchmarkString(BenchmarkLongString);
};
} else if ([name isEqualToString:@"StringShortUnicode"]) {
return ^() {
BenchmarkString(BenchmarkShortStringUnicode);
};
} else if ([name isEqualToString:@"StringLongUnicode"]) {
return ^() {
BenchmarkString(BenchmarkLongStringUnicode);
};
} else if ([name isEqualToString:@"StringRetShort"]) {
return ^() {
BenchmarkStringRetShort();
};
} else if ([name isEqualToString:@"StringRetLong"]) {
return ^() {
BenchmarkStringRetLong();
};
} else if ([name isEqualToString:@"SliceShort"]) {
NSData *s = [Benchmark shortSlice];
return ^() {
BenchmarkSlice(s);
};
} else if ([name isEqualToString:@"SliceLong"]) {
NSData *s = [Benchmark longSlice];
return ^() {
BenchmarkSlice(s);
};
} else {
return nil;
}
}
- (void)run:(NSString*)name n:(long)n {
void (^bench)(void) = [self lookupBenchmark:name];
if (bench == nil) {
NSLog(@"Error: no such benchmark: %@", name);
return;
}
for (int i = 0; i < n; i++) {
bench();
}
}
- (void)runDirect:(NSString*)name n:(long)n {
void (^bench)(void) = [self lookupBenchmark:name];
if (bench == nil) {
NSLog(@"Error: no such benchmark: %@", name);
return;
}
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
for (int i = 0; i < n; i++) {
bench();
}
});
}
@end
@interface benchmarks : XCTestCase
@end
@implementation benchmarks
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
self.continueAfterFailure = NO;
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
[[[XCUIApplication alloc] init] launch];
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testBenchmark {
// Long running unit tests seem to hang. Use an XCTestExpectation and run the Go
// benchmark suite on a GCD thread.
XCTestExpectation *expectation =
[self expectationWithDescription:@"Benchmark"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Benchmarks *b = [[Benchmarks alloc] init];
BenchmarkRunBenchmarks(b);
[expectation fulfill];
});
[self waitForExpectationsWithTimeout:5*60.0 handler:^(NSError *error) {
if (error) {
NSLog(@"Timeout Error: %@", error);
}
}];
}
@end
|