Skip to content

Instantly share code, notes, and snippets.

@spullara
Created May 25, 2010 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spullara/412777 to your computer and use it in GitHub Desktop.
Save spullara/412777 to your computer and use it in GitHub Desktop.
#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