Mercurial > op > Looping
annotate Looping.java @ 7:69b8c75e9c24 default
Scalaのソースコードを追加。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Fri, 18 Feb 2011 10:32:06 +0900 |
parents | 2216535ade9c |
children |
rev | line source |
---|---|
0
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
1 |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
2 public class Looping { |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
3 private int n0; |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
4 public Looping(){ |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
5 n0 = 0; |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
6 } |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
7 public int calc(int n){ |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
8 int n1 = n0 + (1 - 2*(n%2)); |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
9 n0 = n; |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
10 return n1; |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
11 } |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
12 public static void main(String[] args) { |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
13 Looping l = new Looping(); |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
14 int n = 1; |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
15 long t1, t2; |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
16 t1 = System.currentTimeMillis(); |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
17 for(int c=0;c<Integer.MAX_VALUE;c++){ |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
18 n = l.calc(n); |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
19 } |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
20 t2 = System.currentTimeMillis(); |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
21 System.out.println(n + "\nJava\t" + (float)(t2 - t1)/1000); |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
22 } |
2216535ade9c
メンバー関数/メソッド呼び出しのベンチマーク。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
23 } |