diff Looping.java @ 0:2216535ade9c

メンバー関数/メソッド呼び出しのベンチマーク。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Tue, 15 Feb 2011 13:47:19 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Looping.java	Tue Feb 15 13:47:19 2011 +0900
@@ -0,0 +1,23 @@
+
+public class Looping {
+	private int n0;
+	public Looping(){
+		n0 = 0;
+	}
+	public int calc(int n){
+		int n1 = n0 + (1 - 2*(n%2));
+		n0 = n;
+		return n1;
+	}
+	public static void main(String[] args) {
+		Looping l = new Looping();
+		int n = 1;
+		long t1, t2;
+		t1 = System.currentTimeMillis();
+		for(int c=0;c<Integer.MAX_VALUE;c++){
+			n = l.calc(n);
+		}
+		t2 = System.currentTimeMillis();
+		System.out.println(n + "\nJava\t" + (float)(t2 - t1)/1000);
+	}
+}