aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/grothoff/RunaboutBenchmark.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/grothoff/RunaboutBenchmark.java')
-rw-r--r--src/test/java/org/grothoff/RunaboutBenchmark.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/test/java/org/grothoff/RunaboutBenchmark.java b/src/test/java/org/grothoff/RunaboutBenchmark.java
new file mode 100644
index 0000000..18f456d
--- /dev/null
+++ b/src/test/java/org/grothoff/RunaboutBenchmark.java
@@ -0,0 +1,82 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21package org.grothoff;
22
23
24public class RunaboutBenchmark {
25
26 public static class MyRunabout extends Runabout {
27 public void visit(String s) {
28
29 }
30 public void visit(Integer i) {
31
32 }
33 }
34
35
36 public static void main(String[] args) {
37 final int runs = 5000000;
38
39 Runabout r = new MyRunabout();
40
41 long start = System.currentTimeMillis();
42
43 Integer integer = 42;
44 for (int i = 0; i < runs; ++i) {
45 r.visitAppropriate("foo");
46 r.visitAppropriate(integer);
47 }
48
49 long end = System.currentTimeMillis();
50
51 long duration1 = end - start;
52
53
54 Runabout r2 = new Runabout() {
55 public void visit(String s) {
56
57 }
58 public void visit(Integer i) {
59
60 }
61 };
62
63
64 start = System.currentTimeMillis();
65
66 for (int i = 0; i < runs; ++i) {
67 r2.visitAppropriate("foo");
68 r2.visitAppropriate(integer);
69 }
70
71 end = System.currentTimeMillis();
72
73 long duration2 = end - start;
74
75
76 System.out.println("Runs: " + runs);
77 System.out.println("public: " + duration1);
78 System.out.println("Anon Inner Class: " + duration2);
79 System.out.println("Overhead: " + duration2 / (double) duration1);
80
81 }
82}