# HG changeset patch # User "uncorrelated zombie" # Date 1297762699 -32400 # Node ID 9d6fb29e41ceec54c9f6347f1a98b0f29784342b # Parent 2216535ade9c2ff4a169aa4af8821166976d9098 Objective-C IMPのベンチマークが抜けていたため、追加。 diff -r 2216535ade9c -r 9d6fb29e41ce Looping-IMP.M --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping-IMP.M Tue Feb 15 18:38:19 2011 +0900 @@ -0,0 +1,49 @@ +#import +#import +#import +#import + +@interface Looping : Object { + int n0; +} +- (id)init; +- (int)calc:(int)n; +@end + +@implementation Looping +- (id)init{ + [super init]; + n0 = 0; + return self; +} +- (int)calc:(int)n { + int n1 = n0 + (1 - 2*(n%2)); + n0 = n; + return n1; +} +@end + +double gettimeofday_sec() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + (double)tv.tv_usec*1e-6; +} + +int main(){ + id o = [[Looping alloc] init]; + int (*calc)(id,SEL,int); + SEL selector = @selector(calc:); +/* calc = (int (*)(id,SEL,int))objc_msg_lookup(o, selector); */ + calc = (int (*)(id,SEL,int))[Looping instanceMethodFor:selector]; + unsigned c; + int n = 1; + double t1, t2; + t1 = gettimeofday_sec(); + for(c=0;c