标签:http os io for ar art cti div
|
1
2
3
4
5
6
7
8
9
|
#define
MULogTimeintervalBegin(INFO) NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];\NSTimeInterval
duration = 0;\NSLog(@"MULogTimeintervalBegin:%@",
INFO)#define
MULogTimeintervalPauseAndLog(INFO) duration = [NSDate timeIntervalSinceReferenceDate] - start;\start
+= duration;\NSLog(@"%@:%f",
INFO, duration);\duration
= 0#define
TESTSCALE 100000 |
|
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
|
-
(void)testArray{ NSMutableArray*
testArray = [NSMutableArray
arrayWithCapacity:TESTSCALE]; for
(NSInteger
i = 1; i <= TESTSCALE; ++i) { [testArray
addObject:[NSString
stringWithFormat:@"%ld",
i]]; } NSLog(@"init:%ld",
[testArray count]); __block
NSMutableString*
sum = [NSMutableString
stringWithCapacity:TESTSCALE]; MULogTimeintervalBegin(@"ArrayTest"); NSUInteger
count = [testArray count]; for
(NSInteger
i = 0; i < count; ++i) { [sum
appendString:[testArray objectAtIndex:i]]; } [sum
setString:@""]; MULogTimeintervalPauseAndLog(@"for
statement"); for(NSString*
item in testArray) { [sum
appendString:item]; } [sum
setString:@""]; MULogTimeintervalPauseAndLog(@"for-in"); [testArray
enumerateObjectsUsingBlock:^(id
obj, NSUInteger
idx, BOOL
*stop) { [sum
appendString:obj]; }]; [sum
setString:@""]; MULogTimeintervalPauseAndLog(@"enumerateBlock");} |
|
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
|
-
(void)testDictionary
{ NSMutableDictionary*
testDic = [NSMutableDictionary
dictionaryWithCapacity:TESTSCALE]; for
(NSInteger
i = 1; i <= TESTSCALE; ++i) { [testDic
setObject:@"test"
forKey:[NSString
stringWithFormat:@"%ld",
i]]; } NSLog(@"init:%ld",
[testDic count]); __block
NSMutableString*
sum = [NSMutableString
stringWithCapacity:TESTSCALE]; MULogTimeintervalBegin(@"DictionaryTest"); for
(NSString*
object in [testDic allValues]) { [sum
appendString:object]; } [sum
setString:@""]; MULogTimeintervalPauseAndLog(@"for
statement allValues"); for
(id
akey in [testDic allKeys]) { [sum
appendString:[testDic objectForKey:akey]]; } [sum
setString:@""]; MULogTimeintervalPauseAndLog(@"for
statement allKeys"); [testDic
enumerateKeysAndObjectsUsingBlock:^(id
key, id
obj, BOOL
*stop) { [sum
appendString:obj]; }
]; MULogTimeintervalPauseAndLog(@"enumeration");} |
|
1
2
3
|
for
(NSInteger
i = 0; i < count; ++i) { [sum
appendString:[testArray objectAtIndex:i]];} |
|
1
2
3
|
for(NSString*
item in testArray) { [sum
appendString:item];} |
|
1
2
3
|
for
(id
akey in [testDic allKeys]) { [sum
appendString:[testDic objectForKey:akey]];} |
oc/object-c/ios哪种遍历NSArray/NSDictionary方式快?测试报告,布布扣,bubuko.com
oc/object-c/ios哪种遍历NSArray/NSDictionary方式快?测试报告
标签:http os io for ar art cti div
原文地址:http://www.cnblogs.com/langtianya/p/3917098.html