comparison Looping.java @ 0:2216535ade9c

メンバー関数/メソッド呼び出しのベンチマーク。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Tue, 15 Feb 2011 13:47:19 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2216535ade9c
1
2 public class Looping {
3 private int n0;
4 public Looping(){
5 n0 = 0;
6 }
7 public int calc(int n){
8 int n1 = n0 + (1 - 2*(n%2));
9 n0 = n;
10 return n1;
11 }
12 public static void main(String[] args) {
13 Looping l = new Looping();
14 int n = 1;
15 long t1, t2;
16 t1 = System.currentTimeMillis();
17 for(int c=0;c<Integer.MAX_VALUE;c++){
18 n = l.calc(n);
19 }
20 t2 = System.currentTimeMillis();
21 System.out.println(n + "\nJava\t" + (float)(t2 - t1)/1000);
22 }
23 }