8 long startTime, nullLoopTime;
12 public void run(String arg) {
14 int[] a =
new int[10];
27 numLoops = (int)(numLoops*1.33);
28 startTime = System.currentTimeMillis();
29 for (
int i=0; i<numLoops; i++) {}
30 nullLoopTime = System.currentTimeMillis() - startTime;
32 }
while (nullLoopTime<250);
35 IJ.
write(
"Timer: " + numLoops +
" iterations (" + nullLoopTime +
"ms)");
36 Timer2 o =
new Timer2();
39 startTime = System.currentTimeMillis();
40 for (
int i=0; i<numLoops; i++) {}
41 showTime(
"null loop");
44 startTime = System.currentTimeMillis();
45 for (
int i=0; i<numLoops; i++) {k = o.getJ();}
46 showTime(
"i=o.getJ()");
49 startTime = System.currentTimeMillis();
50 for (
int i=0; i<numLoops; i++) {k = o.getJFinal();}
51 showTime(
"i=o.getJ() (final)");
54 startTime = System.currentTimeMillis();
55 for (
int i=0; i<numLoops; i++) {k = o.getJClass();}
56 showTime(
"i=o.getJ() (static)");
59 startTime = System.currentTimeMillis();
60 for (
int i=0; i<numLoops; i++) {k = o.j;}
64 startTime = System.currentTimeMillis();
65 for (
int i=0; i<numLoops; i++) {k = Timer2.k;}
66 showTime(
"i=o.j (static)");
69 startTime = System.currentTimeMillis();
70 for (
int i=0; i<numLoops; i++) {k = j;}
74 startTime = System.currentTimeMillis();
75 for (
int i=0; i<numLoops; i++) {k = a[j];}
98 void showTime(String s) {
99 long elapsedTime = System.currentTimeMillis() - startTime - nullLoopTime;
100 IJ.
write(
" " + s +
": " + (elapsedTime*1000000)/numLoops +
" ns");
134 public int getJ() {
return j;}
135 public final int getJFinal() {
return j;}
136 public static int getJClass() {
return k;}