annotate Looping.M @ 7:69b8c75e9c24 default

Scalaのソースコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Fri, 18 Feb 2011 10:32:06 +0900
parents 2216535ade9c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
1 #import <stdio.h>
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
2 #import <objc/Object.h>
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
3 #import <limits.h>
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
4 #import <sys/time.h>
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
5
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
6 @interface Looping : Object {
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
7 int n0;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
8 }
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
9 - (id)init;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
10 - (int)calc:(int)n;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
11 @end
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
12
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
13 @implementation Looping
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
14 - (id)init{
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
15 [super init];
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
16 n0 = 0;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
17 return self;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
18 }
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
19 - (int)calc:(int)n {
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
20 int n1 = n0 + (1 - 2*(n%2));
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
21 n0 = n;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
22 return n1;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
23 }
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
24 @end
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
25
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
26 double gettimeofday_sec()
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
27 {
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
28 struct timeval tv;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
29 gettimeofday(&tv, NULL);
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
30 return tv.tv_sec + (double)tv.tv_usec*1e-6;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
31 }
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
32
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
33 int main(){
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
34 id o = [[Looping alloc] init];
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
35 unsigned c;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
36 int n = 1;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
37 double t1, t2;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
38 t1 = gettimeofday_sec();
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
39 for(c=0;c<INT_MAX;c++){
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
40 n = [o calc:n];
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
41 }
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
42 t2 = gettimeofday_sec();
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
43 printf("%d\nObjective-C\t%f\n", n, t2 - t1);
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
44 return 0;
2216535ade9c メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
45 }