Changeset 10674 in josm for trunk/test/performance


Ignore:
Timestamp:
2016-07-29T22:15:28+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #13239, fix #13240 - Java 8: MapCSS Condition class (patches by michael2402) - gsoc-core

Location:
trunk/test/performance/org/openstreetmap/josm
Files:
1 added
2 edited

Legend:

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

    r9793 r10674  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm;
     3
     4import java.util.ArrayList;
     5import java.util.Collections;
    36
    47import org.openstreetmap.josm.io.XmlWriter;
     
    1114 */
    1215public final class PerformanceTestUtils {
     16    private static final int TIMES_WARMUP = 2;
     17    private static final int TIMES_RUN = 8;
     18
     19    /**
     20     * A helper class that captures the time from object creation until #done() was called.
     21     * @author Michael Zangl
     22     */
     23    public static class PerformanceTestTimerCapture {
     24        private final long time;
     25
     26        protected PerformanceTestTimerCapture() {
     27            time = System.nanoTime();
     28        }
     29
     30        /**
     31         * Get the time since this object was created.
     32         * @return The time.
     33         */
     34        public long getTimeSinceCreation() {
     35            return (System.nanoTime() - time) / 1000000;
     36        }
     37    }
     38
    1339    /**
    1440     * A timer that measures the time from it's creation to the {@link #done()} call.
    1541     * @author Michael Zangl
    1642     */
    17     public static class PerformanceTestTimer {
     43    public static class PerformanceTestTimer extends PerformanceTestTimerCapture {
    1844        private final String name;
    19         private final long time;
    20         private boolean measurementPlotsPlugin = false;
     45        private boolean measurementPlotsPlugin = true;
    2146
    2247        protected PerformanceTestTimer(String name) {
    2348            this.name = name;
    24             time = System.nanoTime();
    2549        }
    2650
     
    3761         */
    3862        public void done() {
    39             long dTime = (System.nanoTime() - time) / 1000000;
     63            long dTime = getTimeSinceCreation();
    4064            if (measurementPlotsPlugin) {
    4165                measurementPlotsPluginOutput(name + "(ms)", dTime);
     
    5074
    5175    /**
    52      * Starts a new performance timer.
     76     * Starts a new performance timer. The timer will output the measurements in a format understood by Jenkins.
     77     * <p>
     78     * The timer can only be used to meassure one value.
    5379     * @param name The name/description of the timer.
    5480     * @return A {@link PerformanceTestTimer} object of which you can call {@link PerformanceTestTimer#done()} when done.
     
    5682    @SuppressFBWarnings(value = "DM_GC", justification = "Performance test code")
    5783    public static PerformanceTestTimer startTimer(String name) {
     84        cleanSystem();
     85        return new PerformanceTestTimer(name);
     86    }
     87
     88    /**
     89     * Runs the given performance test several (approx. 10) times and prints the median run time.
     90     * @param name The name to use in the output
     91     * @param testRunner The test to run
     92     */
     93    public static void runPerformanceTest(String name, Runnable testRunner) {
     94        for (int i = 0; i < TIMES_WARMUP; i++) {
     95            cleanSystem();
     96            PerformanceTestTimerCapture capture = new PerformanceTestTimerCapture();
     97            testRunner.run();
     98            capture.getTimeSinceCreation();
     99        }
     100        ArrayList<Long> times = new ArrayList<>();
     101        for (int i = 0; i < TIMES_RUN; i++) {
     102            cleanSystem();
     103            PerformanceTestTimerCapture capture = new PerformanceTestTimerCapture();
     104            testRunner.run();
     105            times.add(capture.getTimeSinceCreation());
     106        }
     107        System.out.println(times);
     108        Collections.sort(times);
     109        // Sort out e.g. GC during test run.
     110        double avg = times.subList(2, times.size() - 2).stream().mapToLong(l -> l).average().getAsDouble();
     111        measurementPlotsPluginOutput(name, avg);
     112    }
     113
     114    private static void cleanSystem() {
    58115        System.gc();
    59116        System.runFinalization();
    60         return new PerformanceTestTimer(name);
    61117    }
    62118
     
    68124     * @param name the name / title of the measurement
    69125     * @param value the value
    70      * @see https://wiki.jenkins-ci.org/display/JENKINS/Measurement+Plots+Plugin
     126     * @see "https://wiki.jenkins-ci.org/display/JENKINS/Measurement+Plots+Plugin"
    71127     */
    72128    public static void measurementPlotsPluginOutput(String name, double value) {
  • trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSourceFilterTest.java

    r10222 r10674  
    104104        data.generateDataSet();
    105105        CssGenerator css = new CssGenerator(data).addKeyValueRules(TEST_RULE_COUNT);
    106         runTest(data, css, "only key=value rules", false);
     106        runTest(data, css, "only key=value rules");
    107107    }
    108108
     
    115115        data.generateDataSet();
    116116        CssGenerator css = new CssGenerator(data).addHasKeyRules(TEST_RULE_COUNT);
    117         runTest(data, css, "only has key rules", false);
     117        runTest(data, css, "only has key rules");
    118118    }
    119119
     
    126126        data.generateDataSet();
    127127        CssGenerator css = new CssGenerator(data).addKeyRegexpRules(TEST_RULE_COUNT);
    128         runTest(data, css, "regular expressions", true);
     128        runTest(data, css, "regular expressions");
    129129    }
    130130
     
    137137        data.generateDataSet();
    138138        CssGenerator css = new CssGenerator(data).addIsTrueRules(TEST_RULE_COUNT);
    139         runTest(data, css, "is true", false);
     139        runTest(data, css, "is true");
    140140    }
    141141
    142     private void runTest(KeyValueDataGenerator data, CssGenerator css, String description, boolean measurementPlotsPlugin) {
     142    private void runTest(KeyValueDataGenerator data, CssGenerator css, String description) {
    143143        MapCSSStyleSource source = new MapCSSStyleSource(css.getCss());
    144144        PerformanceTestTimer timer = PerformanceTestUtils.startTimer("MapCSSStyleSource#loadStyleSource(...) for " + description);
     
    146146        timer.done();
    147147
    148         if (measurementPlotsPlugin) {
    149             timer = PerformanceTestUtils.startTimer(description);
    150             timer.setMeasurementPlotsPluginOutput(true);
    151         } else {
    152             timer = PerformanceTestUtils.startTimer(APPLY_CALLS + "x MapCSSStyleSource#apply(...) for " + description);
    153         }
     148        timer = PerformanceTestUtils.startTimer(APPLY_CALLS + "x MapCSSStyleSource#apply(...) for " + description);
    154149        for (int i = 0; i < APPLY_CALLS; i++) {
    155150            MultiCascade mc = new MultiCascade();
Note: See TracChangeset for help on using the changeset viewer.