01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package test;
08:
09: /**
10: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
11: */
12: public class CastBench implements Cast {
13: private static final int NR_INVOCATIONS = 1000000000;
14:
15: public void invoke() {
16: }
17:
18: public void invokeInterface() {
19: }
20:
21: public static void main(String[] args) {
22: CastBench bench = new CastBench();
23: for (int i = 0; i < NR_INVOCATIONS; i++) {
24: bench.invoke();
25: }
26:
27: benchRegularInvoke(bench);
28: benchInterfaceInvoke(bench);
29: benchCastInvoke(bench);
30: }
31:
32: private static void benchCastInvoke(CastBench bench) {
33: long start = System.currentTimeMillis();
34: for (int i = 0; i < NR_INVOCATIONS; i++) {
35: ((Cast) bench).invokeInterface();
36: }
37: long end = System.currentTimeMillis() - start;
38: double time = end / (double) NR_INVOCATIONS;
39: System.out.println("cast invoke = " + time);
40: }
41:
42: private static void benchInterfaceInvoke(Cast bench) {
43: long start = System.currentTimeMillis();
44: for (int i = 0; i < NR_INVOCATIONS; i++) {
45: bench.invokeInterface();
46: }
47: long end = System.currentTimeMillis() - start;
48: double time = end / (double) NR_INVOCATIONS;
49: System.out.println("interface invoke = " + time);
50: }
51:
52: private static void benchRegularInvoke(CastBench bench) {
53: long start = System.currentTimeMillis();
54: for (int i = 0; i < NR_INVOCATIONS; i++) {
55: bench.invoke();
56: }
57: long end = System.currentTimeMillis() - start;
58: double time = end / (double) NR_INVOCATIONS;
59: System.out.println("regular invoke = " + time);
60: }
61: }
|