Created
March 30, 2012 16:43
-
-
Save Machx/2252739 to your computer and use it in GitHub Desktop.
Test isEqual & isEqualToString
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tail end of the results | |
| 2012-03-30 11:36:39.865 Untitled[78506:707] IsEqual: 1438 | isEqualToString 589 | |
| 2012-03-30 11:36:39.875 Untitled[78506:707] IsEqual: 1377 | isEqualToString 590 | |
| 2012-03-30 11:36:39.876 Untitled[78506:707] IsEqual: 956 | isEqualToString 560 | |
| 2012-03-30 11:36:39.877 Untitled[78506:707] IsEqual: 860 | isEqualToString 451 | |
| 2012-03-30 11:36:39.877 Untitled[78506:707] IsEqual: 824 | isEqualToString 433 | |
| 2012-03-30 11:36:39.878 Untitled[78506:707] IsEqual Average 1212 - IsEqualToString Average 619 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| #include <sys/sysctl.h> | |
| #include <unistd.h> | |
| #include <err.h> | |
| #include <errno.h> | |
| #include <stdio.h> | |
| #import <stdarg.h> | |
| #import <mach/mach.h> | |
| #import <mach/mach_time.h> | |
| #import <unistd.h> | |
| uint64_t CWNanoSecondsToExecuteCode(void(^TimeBlock)(void)) | |
| { | |
| uint64_t start = mach_absolute_time(); | |
| TimeBlock(); | |
| uint64_t end = mach_absolute_time(); | |
| uint64_t elapsed = end - start; | |
| mach_timebase_info_data_t info; | |
| mach_timebase_info(&info); | |
| uint64_t nanoSeconds = elapsed * info.numer / info.denom; | |
| return nanoSeconds; | |
| } | |
| @interface NSString (CWNSStringAdditions) | |
| +(NSString *)cw_uuidString; | |
| @end | |
| @implementation NSString (CWNSStringAdditions) | |
| /** | |
| Convenience method for Core Foundations CFUUIDCreate() function | |
| */ | |
| +(NSString *)cw_uuidString | |
| { | |
| NSString *returnedString = nil; | |
| CFUUIDRef uid = CFUUIDCreate(kCFAllocatorDefault); | |
| CFStringRef tmpString = CFUUIDCreateString(kCFAllocatorDefault, uid); | |
| returnedString = [[NSString alloc] initWithString:(__bridge NSString *)tmpString]; | |
| CFRelease(tmpString); | |
| CFRelease(uid); | |
| return returnedString; | |
| } | |
| @end | |
| int main(int argc, char *argv[]) { | |
| @autoreleasepool { | |
| uint64_t isEqualTotal = 0; | |
| uint64_t isEqualToStringTotal = 0; | |
| for (NSInteger i = 0; i < 1000; i++) { | |
| NSString *string1 = [NSString cw_uuidString]; | |
| NSString *string2 = [NSString cw_uuidString]; | |
| uint64_t comp1 = CWNanoSecondsToExecuteCode(^{ | |
| [string1 isEqual:string2]; | |
| }); | |
| uint64_t comp2 = CWNanoSecondsToExecuteCode(^{ | |
| [string1 isEqualToString:string2]; | |
| }); | |
| isEqualTotal += comp1; | |
| isEqualToStringTotal += comp2; | |
| NSLog(@"IsEqual: %llu | isEqualToString %llu",comp1,comp2); | |
| } | |
| uint64_t isEqualAverage = isEqualTotal / 1000; | |
| uint64_t isEqualToStringAverage = isEqualToStringTotal / 1000; | |
| NSLog(@"IsEqual Average %llu - IsEqualToString Average %llu",isEqualAverage,isEqualToStringAverage); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment