-
Notifications
You must be signed in to change notification settings - Fork 127
/
PerformanceTests.m
338 lines (285 loc) · 9.28 KB
/
PerformanceTests.m
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
//
// PerformanceTests.m
// Stinger_Tests
//
// Created by 李永光 on 2019/12/11.
// Copyright © 2019 Assuner-Lee. All rights reserved.
//
#import <XCTest/XCTest.h>
#import <Stinger/Stinger.h>
#import <Aspects/Aspects.h>
@interface TestClassC : NSObject
- (void)methodBeforeA;
- (void)methodA;
- (void)methodAfterA;
- (void)methodA1;
- (void)methodB1;
- (void)methodA2;
- (void)methodB2;
- (void)methodA3:(NSString *)str num:(double)num rect:(CGRect)rect;
- (void)methodB3:(NSString *)str num:(double)num rect:(CGRect)rect;
- (NSString *)methodA4;
- (NSString *)methodB4;
- (NSString *)methodA5:(NSString *)str num:(double)num rect:(CGRect)rect;
- (NSString *)methodB5:(NSString *)str num:(double)num rect:(CGRect)rect;
- (NSString *)methodC:(NSString *)str;
- (NSString *)methodD:(NSString *)str;
@end
@implementation TestClassC
- (void)methodBeforeA {
}
- (void)methodA {
}
- (void)methodAfterA {
}
- (void)methodA1 {
}
- (void)methodB1 {
}
- (void)methodA2 {
}
- (void)methodB2 {
}
- (void)methodA3:(NSString *)str num:(double)num rect:(CGRect)rect {
}
- (void)methodB3:(NSString *)str num:(double)num rect:(CGRect)rect {
}
- (NSString *)methodA4 {
return @"";
}
- (NSString *)methodB4 {
return @"";
}
- (NSString *)methodA5:(NSString *)str num:(double)num rect:(CGRect)rect {
return @"";
}
- (NSString *)methodB5:(NSString *)str num:(double)num rect:(CGRect)rect {
return @"";
}
- (NSString *)methodC:(NSString *)str {
return [str stringByAppendingFormat:@"xx"];
}
- (NSString *)methodD:(NSString *)str {
return [str stringByAppendingFormat:@"xx"];
}
@end
@interface PerformanceTests : XCTestCase
@end
@implementation PerformanceTests
- (void)testaBlankMethod {
[self measureBlock:^{
for (NSInteger i = 0; i < 1000000; i++) {
}
}];
}
- (void)testMethodA {
TestClassC *object1 = [TestClassC new];
[self measureBlock:^{
for (NSInteger i = 0; i < 1000000; i++) {
[object1 methodBeforeA];
[object1 methodA];
[object1 methodAfterA];
}
}];
}
- (void)testStingerHookMethodA1 {
[TestClassC st_hookInstanceMethod:@selector(methodA1) option:STOptionBefore usingIdentifier:@"hook methodA1 before" withBlock:^(id<StingerParams> params) {
}];
[TestClassC st_hookInstanceMethod:@selector(methodA1) option:STOptionAfter usingIdentifier:@"hook methodA1 After" withBlock:^(id<StingerParams> params) {
}];
TestClassC *object1 = [TestClassC new];
[self measureBlock:^{
for (NSInteger i = 0; i < 1000000; i++) {
[object1 methodA1];
}
}];
}
- (void)testAspectHookMethodB1 {
[TestClassC aspect_hookSelector:@selector(methodB1) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> params) {
} error:nil];
[TestClassC aspect_hookSelector:@selector(methodB1) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> params) {
} error:nil];
TestClassC *object1 = [TestClassC new];
[self measureBlock:^{
for (NSInteger i = 0; i < 1000000; i++) {
[object1 methodB1];
}
}];
}
- (void)testStingerHookMethodA2 {
TestClassC *object1 = [TestClassC new];
[object1 st_hookInstanceMethod:@selector(methodA2) option:STOptionBefore usingIdentifier:@"hook methodA2 before" withBlock:^(id<StingerParams> params) {
}];
[object1 st_hookInstanceMethod:@selector(methodA2) option:STOptionAfter usingIdentifier:@"hook methodA2 After" withBlock:^(id<StingerParams> params) {
}];
[self measureBlock:^{
for (NSInteger i = 0; i < 1000000; i++) {
[object1 methodA2];
}
}];
}
- (void)testAspectHookMethodB2 {
TestClassC *object1 = [TestClassC new];
[object1 aspect_hookSelector:@selector(methodB2) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> params) {
} error:nil];
[object1 aspect_hookSelector:@selector(methodB2) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> params) {
} error:nil];
[self measureBlock:^{
for (NSInteger i = 0; i < 1000000; i++) {
[object1 methodB2];
}
}];
}
//- (void)testOne {
// [self measureBlock:^{
// for (NSInteger i = 0; i < 1000000; i++) {
// NSString *str = @"";
// double num = 0.1;
// CGRect rect = CGRectMake(1, 1, 1.1, 1.1);
// }
// }];
//}
//- (void)testMethodA3 {
// [TestClassC st_hookInstanceMethod:@selector(methodA3:num:rect:) option:STOptionBefore usingIdentifier:@"hook methodA3 before" withBlock:^(id<StingerParams> params, NSString *str, double num, CGRect rect) {
// }];
// [TestClassC st_hookInstanceMethod:@selector(methodA3:num:rect:) option:STOptionAfter usingIdentifier:@"hook methodA3 After" withBlock:^(id<StingerParams> params, NSString *str, double num, CGRect rect) {
// }];
//
// TestClassC *object1 = [TestClassC new];
// NSString *str = @"";
// double num = 0.1;
// CGRect rect = CGRectMake(1, 1, 1.1, 1.1);
// [self measureBlock:^{
// for (NSInteger i = 0; i < 1000000; i++) {
// [object1 methodA3:str num:num rect:rect];
// }
// }];
//}
//
//
//
//- (void)testMethodB3 {
// [TestClassC aspect_hookSelector:@selector(methodB3:num:rect:) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> params, NSString *str, double num, CGRect rect) {
// } error:nil];
// [TestClassC aspect_hookSelector:@selector(methodB3:num:rect:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> params, NSString *str, double num, CGRect rect) {
// } error:nil];
//
// TestClassC *object1 = [TestClassC new];
// NSString *str = @"";
// double num = 0.1;
// CGRect rect = CGRectMake(1, 1, 1.1, 1.1);
// [self measureBlock:^{
// for (NSInteger i = 0; i < 1000000; i++) {
// [object1 methodB3:str num:num rect:rect];
// }
// }];
//}
//
//
//- (void)testMethodA4 {
// [TestClassC st_hookInstanceMethod:@selector(methodA4) option:STOptionBefore usingIdentifier:@"hook methodA4 before" withBlock:^(id<StingerParams> params) {
// }];
// [TestClassC st_hookInstanceMethod:@selector(methodA4) option:STOptionAfter usingIdentifier:@"hook methodA4 After" withBlock:^(id<StingerParams> params) {
// }];
//
// TestClassC *object1 = [TestClassC new];
// [self measureBlock:^{
// for (NSInteger i = 0; i < 1000000; i++) {
// [object1 methodA4];
// }
// }];
//}
//
//
//- (void)testMethodB4 {
// [TestClassC aspect_hookSelector:@selector(methodB4) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> params) {
// } error:nil];
// [TestClassC aspect_hookSelector:@selector(methodB4) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> params) {
// } error:nil];
//
// TestClassC *object1 = [TestClassC new];
// [self measureBlock:^{
// for (NSInteger i = 0; i < 1000000; i++) {
// [object1 methodB4];
// }
// }];
//}
//
//
//- (void)testMethodA5 {
// [TestClassC st_hookInstanceMethod:@selector(methodA5:num:rect:) option:STOptionBefore usingIdentifier:@"hook methodA5 before" withBlock:^(id<StingerParams> params, NSString *str, double num, CGRect rect) {
// }];
// [TestClassC st_hookInstanceMethod:@selector(methodA5:num:rect:) option:STOptionAfter usingIdentifier:@"hook methodA5 After" withBlock:^(id<StingerParams> params, NSString *str, double num, CGRect rect) {
// }];
//
// TestClassC *object1 = [TestClassC new];
// NSString *str = @"";
// double num = 0.1;
// CGRect rect = CGRectMake(1, 1, 1.1, 1.1);
// [self measureBlock:^{
// for (NSInteger i = 0; i < 1000000; i++) {
// [object1 methodA5:str num:num rect:rect];
// }
// }];
//}
//
//
//- (void)testMethodB5 {
// [TestClassC aspect_hookSelector:@selector(methodB5:num:rect:) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> params, NSString *str, double num, CGRect rect) {
// } error:nil];
// [TestClassC aspect_hookSelector:@selector(methodB5:num:rect:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> params, NSString *str, double num, CGRect rect) {
// } error:nil];
//
// TestClassC *object1 = [TestClassC new];
// NSString *str = @"";
// double num = 0.1;
// CGRect rect = CGRectMake(1, 1, 1.1, 1.1);
// [self measureBlock:^{
// for (NSInteger i = 0; i < 1000000; i++) {
// [object1 methodB5:str num:num rect:rect];
// }
// }];
//}
//
//
//
//
//
//
//
//
//- (void)testStingerHookMethodC {
// TestClassC *object1 = [TestClassC new];
// __block NSString *oldRet, *ret;
// [TestClassC st_hookInstanceMethod:@selector(methodC:) option:STOptionInstead usingIdentifier:@"hook methodC instead" withBlock:^NSString *(id<StingerParams> params, NSString *str) {
// [params invokeAndGetOriginalRetValue:&oldRet];
// ret = [oldRet stringByAppendingFormat:@"++"];
// return ret;
// }];
//
// __block NSString *result;
// [self measureBlock:^{
// for (NSInteger i = 0; i < 1000000; i++) {
// result = [object1 methodC:@""];
// }
// }];
//}
//
//- (void)testAspectHookMethodD {
// __block NSString *oldRet, *ret;
// [TestClassC aspect_hookSelector:@selector(methodD:) withOptions:AspectPositionInstead usingBlock:^(id<AspectInfo> params, NSString *str) {
// [params.originalInvocation invoke];
// [params.originalInvocation getReturnValue:&oldRet];
// ret = [oldRet stringByAppendingFormat:@"++"];
// [params.originalInvocation setReturnValue:&ret];
// } error:nil];
//
// TestClassC *object1 = [TestClassC new];
// __block NSString *result;
// [self measureBlock:^{
// for (NSInteger i = 0; i < 1000000; i++) {
// result = [object1 methodD:@""];
// }
// }];
//}
@end