Changeset 10674 in josm for trunk/test/performance
- Timestamp:
- 2016-07-29T22:15:28+02:00 (8 years ago)
- 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 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm; 3 4 import java.util.ArrayList; 5 import java.util.Collections; 3 6 4 7 import org.openstreetmap.josm.io.XmlWriter; … … 11 14 */ 12 15 public 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 13 39 /** 14 40 * A timer that measures the time from it's creation to the {@link #done()} call. 15 41 * @author Michael Zangl 16 42 */ 17 public static class PerformanceTestTimer {43 public static class PerformanceTestTimer extends PerformanceTestTimerCapture { 18 44 private final String name; 19 private final long time; 20 private boolean measurementPlotsPlugin = false; 45 private boolean measurementPlotsPlugin = true; 21 46 22 47 protected PerformanceTestTimer(String name) { 23 48 this.name = name; 24 time = System.nanoTime();25 49 } 26 50 … … 37 61 */ 38 62 public void done() { 39 long dTime = (System.nanoTime() - time) / 1000000;63 long dTime = getTimeSinceCreation(); 40 64 if (measurementPlotsPlugin) { 41 65 measurementPlotsPluginOutput(name + "(ms)", dTime); … … 50 74 51 75 /** 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. 53 79 * @param name The name/description of the timer. 54 80 * @return A {@link PerformanceTestTimer} object of which you can call {@link PerformanceTestTimer#done()} when done. … … 56 82 @SuppressFBWarnings(value = "DM_GC", justification = "Performance test code") 57 83 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() { 58 115 System.gc(); 59 116 System.runFinalization(); 60 return new PerformanceTestTimer(name);61 117 } 62 118 … … 68 124 * @param name the name / title of the measurement 69 125 * @param value the value 70 * @see https://wiki.jenkins-ci.org/display/JENKINS/Measurement+Plots+Plugin126 * @see "https://wiki.jenkins-ci.org/display/JENKINS/Measurement+Plots+Plugin" 71 127 */ 72 128 public static void measurementPlotsPluginOutput(String name, double value) { -
trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSourceFilterTest.java
r10222 r10674 104 104 data.generateDataSet(); 105 105 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"); 107 107 } 108 108 … … 115 115 data.generateDataSet(); 116 116 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"); 118 118 } 119 119 … … 126 126 data.generateDataSet(); 127 127 CssGenerator css = new CssGenerator(data).addKeyRegexpRules(TEST_RULE_COUNT); 128 runTest(data, css, "regular expressions" , true);128 runTest(data, css, "regular expressions"); 129 129 } 130 130 … … 137 137 data.generateDataSet(); 138 138 CssGenerator css = new CssGenerator(data).addIsTrueRules(TEST_RULE_COUNT); 139 runTest(data, css, "is true" , false);139 runTest(data, css, "is true"); 140 140 } 141 141 142 private void runTest(KeyValueDataGenerator data, CssGenerator css, String description , boolean measurementPlotsPlugin) {142 private void runTest(KeyValueDataGenerator data, CssGenerator css, String description) { 143 143 MapCSSStyleSource source = new MapCSSStyleSource(css.getCss()); 144 144 PerformanceTestTimer timer = PerformanceTestUtils.startTimer("MapCSSStyleSource#loadStyleSource(...) for " + description); … … 146 146 timer.done(); 147 147 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); 154 149 for (int i = 0; i < APPLY_CALLS; i++) { 155 150 MultiCascade mc = new MultiCascade();
Note:
See TracChangeset
for help on using the changeset viewer.