source: josm/trunk/test/performance/org/openstreetmap/josm/PerformanceTestUtils.java@ 8632

Last change on this file since 8632 was 8632, checked in by Don-vip, 9 years ago

update Checkstyle to 6.8.1, update Eclipse project, fix checkstyle issues

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm;
3
4/**
5 * Timer utilities for performance tests.
6 * @author Michael Zangl
7 */
8public final class PerformanceTestUtils {
9 /**
10 * A timer that measures the time from it's creation to the {@link #done()} call.
11 * @author Michael Zangl
12 */
13 public static class PerformanceTestTimer {
14 private String name;
15 private long time;
16
17 protected PerformanceTestTimer(String name) {
18 this.name = name;
19 time = System.nanoTime();
20 }
21
22 /**
23 * Prints the time since this timer was created.
24 */
25 public void done() {
26 long dTime = System.nanoTime() - time;
27 System.out.println("TIMER " + name + ": " + dTime / 1000000 + "ms");
28 }
29 }
30
31 private PerformanceTestUtils() {
32 }
33
34 /**
35 * Starts a new performance timer.
36 * @param name The name/description of the timer.
37 * @return A {@link PerformanceTestTimer} object of which you can call {@link PerformanceTestTimer#done()} when done.
38 */
39 public static PerformanceTestTimer startTimer(String name) {
40 System.gc();
41 System.runFinalization();
42 return new PerformanceTestTimer(name);
43 }
44}
Note: See TracBrowser for help on using the repository browser.