Created
May 25, 2010 04:56
-
-
Save spullara/412777 to your computer and use it in GitHub Desktop.
This file contains 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
#include <assert.h> | |
#import <Cocoa/Cocoa.h> | |
#import <Foundation/Foundation.h> | |
#import <CoreServices/CoreServices.h> | |
#include <mach/mach.h> | |
#include <mach/mach_time.h> | |
#include <unistd.h> | |
@interface ObjCBenchmark : NSObject | |
{ | |
} | |
@end | |
@implementation ObjCBenchmark | |
+ (int)innerCompareTo { | |
NSString *str1, *str2, *str3, *str4; | |
str2 = @"vm-guld vm-guld vm-guldx"; | |
str3 = @"vm-guld vm-guld vm-guldx"; | |
str1 = @"vm-guld vm-guld vm-guld"; | |
str4 = @"adadaskasdjierudks"; | |
int t = 0; | |
t += [str1 compare:str2]; | |
t += [str2 compare:str3]; | |
t += [str3 compare:str4]; | |
return t; | |
} | |
+(double)testCompareTo:(int)loops { | |
int count = 0; | |
int j, i; | |
int total = 0; | |
double start = [NSDate timeIntervalSinceReferenceDate]; | |
for (j = 0; j < loops; j++) { | |
count++; | |
for (i = 0; i < 100; i++) { | |
total += [self innerCompareTo]; | |
} | |
} | |
double elapsed = [NSDate timeIntervalSinceReferenceDate] - start; | |
printf("%lf\n", elapsed); | |
return ((double)count)/elapsed; | |
} | |
+(double)run | |
{ | |
return [self testCompareTo:100000]; | |
} | |
@end | |
int main (int argc, const char * argv[]) { | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
// insert code here... | |
for (int i = 0; i < 2; i ++) { | |
printf("%lf\n", [ObjCBenchmark run]); | |
} | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment