• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package test1;
2 
3 class BenchProceed2 {
calc2()4     public void calc2() {
5         for (long i = 0; i < 10000000; ++i)
6             Math.sqrt(i);
7     }
8 }
9 
10 public class BenchProceed {
11     public double d;
12     public java.lang.reflect.Method calcM;
13 
14     public static final int N = 1000000;
15 
BenchProceed()16     public BenchProceed() throws Exception {
17         calcM = this.getClass().getDeclaredMethod("calc", new Class[0]);
18     }
19 
calc()20     public void calc() {
21         d = Math.sqrt(3.0);
22     }
23 
p()24     public int p() {
25         long time = System.currentTimeMillis();
26         for (int i = N; i > 0; --i)
27             calc();
28 
29         long time2 = System.currentTimeMillis();
30         return (int)(time2 - time);
31     }
32 
q()33     public int q() {
34         long time = System.currentTimeMillis();
35         for (int i = N; i > 0; --i)
36             calc();
37 
38         long time2 = System.currentTimeMillis();
39         return (int)(time2 - time);
40     }
41 
s()42     public int s() {
43         BenchProceed2 bp = new BenchProceed2();
44         for (int i = 0; i < 5; ++i)
45             bp.calc2();
46 
47         return 0;
48     }
49 
t()50     public int t() {
51         BenchProceed2 bp = new BenchProceed2();
52         for (int i = 0; i < 5; ++i)
53             bp.calc2();
54 
55         return 0;
56     }
57 
before(Object[] args)58     public void before(Object[] args) {
59     }
60 
replace(Object[] args)61     public Object replace(Object[] args) {
62         try {
63             return calcM.invoke(this, args);
64         }
65         catch (Exception e) {
66             System.out.println(e);
67         }
68 
69         return null;
70     }
71 
main(String[] args)72     public static void main(String[] args) throws Exception {
73         BenchProceed bp = new BenchProceed();
74         System.out.println("iteration " + N);
75         System.out.println("p (msec) " + bp.p());
76         System.out.println("q (msec) " + bp.q());
77         System.out.println("p (msec) " + bp.p());
78         System.out.println("q (msec) " + bp.q());
79 
80         bp.s();
81         bp.t();
82     }
83 }
84