Objective-CSeveral string processing SpeedsData TestingIs the content to be introduced in this article. There is not much content in this article, mainly based on code implementationDataOfTestFor more information, see the detailed code in this article.
Testing Machine 2.4 GHz Intel Core 2Duo 2 GB 667 MHz DDR2 GCC 4.2
- -(Void) testStringSpeed :( id) sender
- {
- NSAID utoreleasepool * pool = [[NSAID utoreleasepool alloc] init];
- [TextField setStringValue: @ ""];
- Int testi, testnum = 10;
- Float c, tm = 0.0;
- For (testi = 0; testi <testnum; testi ++ ){
- NSDate * beg = [NSDate date];
- Int I, n = 10000000;
- For (I = 0; I <n; I ++ ){
- // AV = 0.030204
- /*
- {
- // Avg = 0.594266 the memory remains stable
- NSString * t = [[NSString alloc] initWithString: @ "abccc"];
- [T release];
- }*/
- /*
- {
- // Avg = 0.026101 the memory remains stable
- NSString * astring = @ "abcc ";
- }*/
- /*
- {
- // Avg = 0.278873 the memory remains stable
- NSString * astring = [[NSString alloc] init];
- Astring = @ "abcc ";
- [Astring release];
- }*/
- /*
- {
- // Avg = 2.737541 the memory remains stable
- Char * Cstring = "abcc ";
- NSString * astring = [[NSString alloc] initWithCString: Cstring];
- [Astring release];
- }*/
- /*
- {
- // Avg = 3.619728 the memory is growing too fast
- NSString * a = [NSString stringWithString: @ "abcc"];
- }*/
- /*
- {
- // Too long, the memory grows too fast
- NSString * a = [NSString stringWithFormat: @ "abcc % d", I];
- }
- */
- /*
- {
- // Avg = 0.034632 the memory remains stable
- Char a [] = "abcc ";
- }*/
- /*
- {
- // Memory usage increases slightly by 18.1555
- NSString * a = [[NSString alloc] initWithFormat: @ "abcc % d", I];
- [A release];
- }*/
- /*
- {
- // Avg = 2.276076 the memory remains stable
- Char a [32];
- Sprintf (a, "abcc % d", I );
- }*/
- /*
- {
- // Too long, the memory grows too fast
- NSMutableString * a = [[NSMutableString alloc] init];
- [A stringByAppendingFormat: @ "abcc % d", I];
- [A release];
- }*/
- }
- C = [[NSDate date] timeIntervalSinceDate: beg];
- Tm + = c;
- [TextField setStringValue: [NSString stringWithFormat: @ "% @ \ n % d = % f", [textField stringValue], testi + 1, c];
- }
- [TextField setStringValue: [NSString stringWithFormat: @ "% @ \ navg = % f", [textField stringValue], (float) tm/testnum];
- [Pool release];
- }
Summary: AnalysisObjective-CSeveral string processing SpeedsData TestingI hope you can read this article to help me!