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