Changeset 17618 in josm for trunk/test/performance/org


Ignore:
Timestamp:
2021-03-21T13:56:19+01:00 (3 years ago)
Author:
simon04
Message:

see #4626 - PerformanceTestUtils.PerformanceTestTimer: use Stopwatch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/performance/org/openstreetmap/josm/PerformanceTestUtils.java

    r17617 r17618  
    1616
    1717import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     18import org.openstreetmap.josm.tools.Stopwatch;
    1819
    1920/**
     
    4445
    4546    /**
    46      * A helper class that captures the time from object creation until #done() was called.
    47      * @author Michael Zangl
    48      */
    49     public static class PerformanceTestTimerCapture {
    50         private final long time;
    51 
    52         protected PerformanceTestTimerCapture() {
    53             time = System.nanoTime();
    54         }
    55 
    56         /**
    57          * Get the time since this object was created.
    58          * @return The time.
    59          */
    60         public long getTimeSinceCreation() {
    61             return (System.nanoTime() - time) / 1000000;
    62         }
    63     }
    64 
    65     /**
    6647     * A timer that measures the time from it's creation to the {@link #done()} call.
    6748     * @author Michael Zangl
    6849     */
    69     public static class PerformanceTestTimer extends PerformanceTestTimerCapture {
     50    public static class PerformanceTestTimer {
     51        private final Stopwatch stopwatch = Stopwatch.createStarted();
    7052        private final String name;
    7153        private boolean measurementPlotsPlugin = true;
     
    8769         */
    8870        public void done() {
    89             long dTime = getTimeSinceCreation();
     71            long dTime = stopwatch.elapsed();
    9072            if (measurementPlotsPlugin) {
    9173                measurementPlotsPluginOutput(name + "(ms)", dTime);
     
    120102        for (int i = 0; i < TIMES_WARMUP; i++) {
    121103            cleanSystem();
    122             PerformanceTestTimerCapture capture = new PerformanceTestTimerCapture();
     104            Stopwatch capture = Stopwatch.createStarted();
    123105            testRunner.run();
    124             capture.getTimeSinceCreation();
     106            capture.elapsed();
    125107        }
    126108        ArrayList<Long> times = new ArrayList<>();
    127109        for (int i = 0; i < TIMES_RUN; i++) {
    128110            cleanSystem();
    129             PerformanceTestTimerCapture capture = new PerformanceTestTimerCapture();
     111            Stopwatch stopwatch = Stopwatch.createStarted();
    130112            testRunner.run();
    131             times.add(capture.getTimeSinceCreation());
     113            times.add(stopwatch.elapsed());
    132114        }
    133115        System.out.println(times);
Note: See TracChangeset for help on using the changeset viewer.