Parsing Objective-C string processing speed data testing

Source: Internet
Author: User

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

 
 
  1. -(Void) testStringSpeed :( id) sender
  2. {
  3. NSAID utoreleasepool * pool = [[NSAID utoreleasepool alloc] init];
  4. [TextField setStringValue: @ ""];
  5. Int testi, testnum = 10;
  6. Float c, tm = 0.0;
  7. For (testi = 0; testi <testnum; testi ++ ){
  8. NSDate * beg = [NSDate date];
  9. Int I, n = 10000000;
  10. For (I = 0; I <n; I ++ ){
  11. // AV = 0.030204
  12. /*
  13. {
  14. // Avg = 0.594266 the memory remains stable
  15. NSString * t = [[NSString alloc] initWithString: @ "abccc"];
  16. [T release];
  17. }*/
  18. /*
  19. {
  20. // Avg = 0.026101 the memory remains stable
  21. NSString * astring = @ "abcc ";
  22. }*/
  23. /*
  24. {
  25. // Avg = 0.278873 the memory remains stable
  26. NSString * astring = [[NSString alloc] init];
  27. Astring = @ "abcc ";
  28. [Astring release];
  29. }*/
  30. /*
  31. {
  32. // Avg = 2.737541 the memory remains stable
  33. Char * Cstring = "abcc ";
  34. NSString * astring = [[NSString alloc] initWithCString: Cstring];
  35. [Astring release];
  36. }*/
  37. /*
  38. {
  39. // Avg = 3.619728 the memory is growing too fast
  40. NSString * a = [NSString stringWithString: @ "abcc"];
  41. }*/
  42. /*
  43. {
  44. // Too long, the memory grows too fast
  45. NSString * a = [NSString stringWithFormat: @ "abcc % d", I];
  46. }
  47. */
  48. /*
  49. {
  50. // Avg = 0.034632 the memory remains stable
  51. Char a [] = "abcc ";
  52. }*/
  53. /*
  54. {
  55. // Memory usage increases slightly by 18.1555
  56. NSString * a = [[NSString alloc] initWithFormat: @ "abcc % d", I];
  57. [A release];
  58. }*/
  59. /*
  60. {
  61. // Avg = 2.276076 the memory remains stable
  62. Char a [32];
  63. Sprintf (a, "abcc % d", I );
  64. }*/
  65. /*
  66. {
  67. // Too long, the memory grows too fast
  68. NSMutableString * a = [[NSMutableString alloc] init];
  69. [A stringByAppendingFormat: @ "abcc % d", I];
  70. [A release];
  71. }*/
  72. }
  73. C = [[NSDate date] timeIntervalSinceDate: beg];
  74. Tm + = c;
  75. [TextField setStringValue: [NSString stringWithFormat: @ "% @ \ n % d = % f", [textField stringValue], testi + 1, c];
  76. }
  77. [TextField setStringValue: [NSString stringWithFormat: @ "% @ \ navg = % f", [textField stringValue], (float) tm/testnum];
  78. [Pool release];
  79. }

Summary: AnalysisObjective-CSeveral string processing SpeedsData TestingI hope you can read this article to help me!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.