View Javadoc

1   /* ==========================================
2    * JperfProbe : Java Performance Probes
3    * ==========================================
4    *
5    * Project Info:  http://jperfprobe.sourceforge.net/
6    * Project Lead:  Tor-Erik Larsen (http://sourceforge.net/users/uptime62)
7    *
8    * (C) Copyright 2005, by Tor-Erik Larsen and Contributors.
9    *
10   * This library is free software; you can redistribute it and/or modify it
11   * under the terms of the GNU Lesser General Public License as published by
12   * the Free Software Foundation; either version 2.1 of the License, or
13   * (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful, but
16   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17   * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18   * License for more details.
19   *
20   * You should have received a copy of the GNU Lesser General Public License
21   * along with this library; if not, write to the Free Software Foundation, Inc.,
22   * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
23   */
24  package net.sf.jperfprobe;
25  
26  public class Mockup {
27  
28      public static void main(String[] args) {
29          int max = 10000;
30          // warm up
31          StaticProbeManager.setPresentation(ProbeManagerImpl.Presentation.MICROS);
32  
33          StaticProbeManager.getProbeInstance("NULLPROBE");
34          StaticProbeManager.getProbeInstance("START");
35          StaticProbeManager.getProbeInstance("STOP");
36          StaticProbeManager.getProbeInstance("DUMMY");
37  
38          for (int i = 0; i < max; i++) {
39              StaticProbeManager.start("NULLPROBE");
40              StaticProbeManager.stop("NULLPROBE");
41  
42              StaticProbeManager.start("START");
43              StaticProbeManager.start("DUMMY");
44              StaticProbeManager.stop("START");
45  
46              StaticProbeManager.start("STOP");
47              // START SNIPPET: snip-01
48              StaticProbeManager.stop("DUMMY");
49              StaticProbeManager.stop("STOP");
50              // END SNIPPET: snip-01
51          }
52  
53          System.gc();
54  
55          System.out.println("Warmup");
56          System.out.println(StaticProbeManager.toString("NULLPROBE"));
57          System.out.println(StaticProbeManager.toString("START"));
58          System.out.println(StaticProbeManager.toString("STOP"));
59  
60          /*
61          StaticProbeManager.getInstance("NULLPROBE").clearSamples();
62          StaticProbeManager.getInstance("START").clearSamples();
63          StaticProbeManager.getInstance("STOP").clearSamples();
64          */
65          StaticProbeManager.clear();
66  
67          System.out.println("Cleared");
68          System.out.println(StaticProbeManager.toString("NULLPROBE"));
69          System.out.println(StaticProbeManager.toString("START"));
70          System.out.println(StaticProbeManager.toString("STOP"));
71          System.gc();
72  
73          for (int i = 0; i < max; i++) {
74              StaticProbeManager.start("NULLPROBE");
75              StaticProbeManager.stop("NULLPROBE");
76  
77              StaticProbeManager.start("START");
78              StaticProbeManager.start("DUMMY");
79              StaticProbeManager.stop("START");
80  
81              StaticProbeManager.start("STOP");
82              StaticProbeManager.stop("DUMMY");
83              StaticProbeManager.stop("STOP");
84          }
85  
86          System.out.println("Real");
87          System.out.println(StaticProbeManager.toString("NULLPROBE"));
88          System.out.println(StaticProbeManager.toString("START"));
89          System.out.println(StaticProbeManager.toString("STOP"));
90  
91          StaticProbeManager.start("MyProbe");
92          for (int i = 0; i < 1000; i++) {
93              int k = 2 + i / 4 * i;
94          }
95          StaticProbeManager.stop("MyProbe");
96          System.out.println(StaticProbeManager.toString("MyProbe"));
97  
98          long time = 0;
99          long newTime;
100         long smaller = 9999999999999L;
101         long taller = 0;
102 
103         int j = 0;
104         for (int i = 0; i < 100000; i++) {
105             time = System.nanoTime();
106             j = 1;
107             j++;
108             newTime = System.nanoTime();
109 
110             smaller = Math.min(smaller, newTime - time);
111             taller = Math.min(taller, newTime - time);
112         }
113 
114         System.out.println("Smallest nano interval measured: " + smaller);
115         System.out.println("Tallest nano interval measured: " + taller);
116         System.out.println("Current time millis: " + System.currentTimeMillis());
117         System.out.println("Nano time: " + System.nanoTime());
118         System.out.println("j" + j);
119 
120         int COUNT = 1000000;
121         
122         long start = System.nanoTime();
123         long end = start;
124         for (int i = 0; i < COUNT; i++) {
125             end = System.nanoTime();
126         }
127         System.out.println("nanoTime:          " + (end - start) / COUNT + " ns");
128 
129         long dummy = 0;
130         start = System.nanoTime();
131         for (int i = 0; i < COUNT; i++) {
132             dummy = System.currentTimeMillis();
133         }
134         end = System.nanoTime();
135         System.out.println("currentTimeMillis: " + (end - start) / COUNT + " ns");
136 
137 
138     }
139 }
140 
141