annotate Looping-IMP.M @ 1:9d6fb29e41ce

Objective-C IMPのベンチマークが抜けていたため、追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Tue, 15 Feb 2011 18:38:19 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
1 #import <stdio.h>
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
2 #import <objc/Object.h>
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
3 #import <limits.h>
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
4 #import <sys/time.h>
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
5
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
6 @interface Looping : Object {
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
7 int n0;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
8 }
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
9 - (id)init;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
10 - (int)calc:(int)n;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
11 @end
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
12
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
13 @implementation Looping
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
14 - (id)init{
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
15 [super init];
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
16 n0 = 0;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
17 return self;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
18 }
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
19 - (int)calc:(int)n {
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
20 int n1 = n0 + (1 - 2*(n%2));
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
21 n0 = n;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
22 return n1;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
23 }
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
24 @end
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
25
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
26 double gettimeofday_sec()
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
27 {
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
28 struct timeval tv;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
29 gettimeofday(&tv, NULL);
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
30 return tv.tv_sec + (double)tv.tv_usec*1e-6;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
31 }
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
32
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
33 int main(){
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
34 id o = [[Looping alloc] init];
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
35 int (*calc)(id,SEL,int);
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
36 SEL selector = @selector(calc:);
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
37 /* calc = (int (*)(id,SEL,int))objc_msg_lookup(o, selector); */
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
38 calc = (int (*)(id,SEL,int))[Looping instanceMethodFor:selector];
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
39 unsigned c;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
40 int n = 1;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
41 double t1, t2;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
42 t1 = gettimeofday_sec();
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
43 for(c=0;c<INT_MAX;c++){
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
44 n = calc(o, selector, n);
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
45 }
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
46 t2 = gettimeofday_sec();
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
47 printf("%d\nObjective-C\t%f\n", n, t2 - t1);
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
48 return 0;
9d6fb29e41ce Objective-C IMPのベンチマークが抜けていたため、追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
49 }