aboutsummaryrefslogtreecommitdiff
path: root/src/test/test1/BenchProceed.java
blob: c7561811f827488249ea916e99d83d590c32c440 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package test1;

class BenchProceed2 {
    public void calc2() {
        for (long i = 0; i < 10000000; ++i)
            Math.sqrt(i);
    }
}

public class BenchProceed {
    public double d;
    public java.lang.reflect.Method calcM;

    public static final int N = 1000000;

    public BenchProceed() throws Exception {
        calcM = this.getClass().getDeclaredMethod("calc", new Class[0]);
    }

    public void calc() {
        d = Math.sqrt(3.0);
    }

    public int p() {
        long time = System.currentTimeMillis();
        for (int i = N; i > 0; --i)
            calc();

        long time2 = System.currentTimeMillis();
        return (int)(time2 - time);
    }

    public int q() {
        long time = System.currentTimeMillis();
        for (int i = N; i > 0; --i)
            calc();

        long time2 = System.currentTimeMillis();
        return (int)(time2 - time);
    }

    public int s() {
        BenchProceed2 bp = new BenchProceed2();
        for (int i = 0; i < 5; ++i)
            bp.calc2();

        return 0;
    }

    public int t() {
        BenchProceed2 bp = new BenchProceed2();
        for (int i = 0; i < 5; ++i)
            bp.calc2();

        return 0;
    }

    public void before(Object[] args) {
    }

    public Object replace(Object[] args) {
        try {
            return calcM.invoke(this, args);
        }
        catch (Exception e) {
            System.out.println(e);
        }

        return null;
    }

    public static void main(String[] args) throws Exception {
        BenchProceed bp = new BenchProceed();
        System.out.println("iteration " + N);
        System.out.println("p (msec) " + bp.p());
        System.out.println("q (msec) " + bp.q());
        System.out.println("p (msec) " + bp.p());
        System.out.println("q (msec) " + bp.q());

        bp.s();
        bp.t();
    }
}