blob: 69abc306675e3232de49bb86106148e11ddb2f4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package test1;
public class BenchStaticMethod {
public static final int N = 10000000;
public static int foo(int i) {
i /= 100000;
int f = 1;
while (i > 1)
f *= i--;
return f;
}
public static void foo2(int i) {}
public static int num = 0;
public static int test() {
long time = System.currentTimeMillis();
for (int i = N; i > 0; --i)
foo(i);
long time2 = System.currentTimeMillis();
return (int)(time2 - time);
}
public static int orgTest() {
long time = System.currentTimeMillis();
for (int i = N; i > 0; --i)
foo(i);
long time2 = System.currentTimeMillis();
return (int)(time2 - time);
}
public static int handTest() {
long time = System.currentTimeMillis();
for (int i = N; i > 0; --i) {
num += i;
foo(i);
}
long time2 = System.currentTimeMillis();
return (int)(time2 - time);
}
public static void main(String[] args) throws Exception {
System.out.println("orgTest (msec) " + orgTest());
System.out.println("handTest (msec) " + handTest());
System.out.println("test (msec) " + test());
}
}
|