Debian Codegraph @

bind/objc/SeqBench.m

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