I'm doing a "stress test", I need to know how long it takes to do recursive operations in iPhone / iPad.
For example:
//"key" is defined in header.
for(int a=0;a<200;a++){
for(int g=0;g<200;g++){
key = @"hi";
}
}
Do this value assignment (40.000 times) takes 6ms in iPad. But, if I do that:
for(int a=0;a<200;a++){
for(in开发者_运维问答t g=0;g<200;g++){
key = [NSString stringWithFormat:@"%i,%i",a,g];
}
}
It takes almost 1 second!! For my application, I need to do this assignment more faster than this, someone knows another way to do?
for(int a=0;a<200;a++){
for(int g=0;g<200;g++){
char str[10];
snprintf(str, 10, "%d,%d", a,g);
key = [NSString stringWithCString:str encoding:NSASCIIStringEncoding];
}
}
Runs 4 times as fast on my old ipod touch 2g
Time old: 4.303022833333
Time new: 1.117406833333
精彩评论