diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/RenderBenchmarkCollector.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/RenderBenchmarkCollector.java
index 79002ea5b..dc23b7634 100644
|
a
|
b
|
public class RenderBenchmarkCollector {
|
| 64 | 64 | |
| 65 | 65 | @Override |
| 66 | 66 | public void renderStart(double circum) { |
| 67 | | timeStart = System.currentTimeMillis(); |
| | 67 | timeStart = getCurrentTimeMilliseconds(); |
| 68 | 68 | super.renderStart(circum); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | @Override |
| 72 | 72 | public boolean renderSort() { |
| 73 | | timeGenerateDone = System.currentTimeMillis(); |
| | 73 | timeGenerateDone = getCurrentTimeMilliseconds(); |
| 74 | 74 | return super.renderSort(); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | @Override |
| 78 | 78 | public boolean renderDraw(List<StyleRecord> allStyleElems) { |
| 79 | | timeSortingDone = System.currentTimeMillis(); |
| | 79 | timeSortingDone = getCurrentTimeMilliseconds(); |
| 80 | 80 | return super.renderDraw(allStyleElems); |
| 81 | 81 | } |
| 82 | 82 | |
| … |
… |
public class RenderBenchmarkCollector {
|
| 98 | 98 | |
| 99 | 99 | @Override |
| 100 | 100 | public void renderDone() { |
| 101 | | timeFinished = System.currentTimeMillis(); |
| | 101 | timeFinished = getCurrentTimeMilliseconds(); |
| 102 | 102 | super.renderDone(); |
| 103 | 103 | } |
| 104 | 104 | |
| … |
… |
public class RenderBenchmarkCollector {
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| | 114 | public static long getCurrentTimeMilliseconds() { |
| | 115 | return System.nanoTime() / 1000000; // System.currentTimeMillis has low accuracy, sometimes multiples of 16ms |
| | 116 | } |
| | 117 | |
| 114 | 118 | /** |
| 115 | 119 | * A special version of the benchmark class that logs the output to stderr. |
| 116 | 120 | * @author Michael Zangl |
diff --git a/test/performance/org/openstreetmap/josm/gui/mappaint/MapRendererPerformanceTest.java b/test/performance/org/openstreetmap/josm/gui/mappaint/MapRendererPerformanceTest.java
index f2bbfa362..194f4d8b7 100644
|
a
|
b
|
package org.openstreetmap.josm.gui.mappaint;
|
| 3 | 3 | |
| 4 | 4 | import java.awt.Color; |
| 5 | 5 | import java.awt.Graphics2D; |
| | 6 | import java.awt.Point; |
| 6 | 7 | import java.awt.image.BufferedImage; |
| 7 | 8 | import java.io.File; |
| 8 | 9 | import java.io.IOException; |
| 9 | 10 | import java.io.InputStream; |
| 10 | 11 | import java.util.ArrayList; |
| 11 | 12 | import java.util.Collections; |
| | 13 | import java.util.Comparator; |
| 12 | 14 | import java.util.EnumMap; |
| 13 | 15 | import java.util.HashMap; |
| 14 | 16 | import java.util.List; |
| … |
… |
import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
|
| 34 | 36 | import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer.StyleRecord; |
| 35 | 37 | import org.openstreetmap.josm.data.preferences.sources.SourceEntry; |
| 36 | 38 | import org.openstreetmap.josm.data.projection.ProjectionRegistry; |
| 37 | | import org.openstreetmap.josm.gui.MainApplication; |
| 38 | 39 | import org.openstreetmap.josm.gui.NavigatableComponent; |
| 39 | 40 | import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting; |
| 40 | 41 | import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader; |
| … |
… |
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
| 45 | 46 | import org.openstreetmap.josm.io.Compression; |
| 46 | 47 | import org.openstreetmap.josm.io.OsmReader; |
| 47 | 48 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
| 48 | | import org.openstreetmap.josm.tools.Logging; |
| 49 | 49 | |
| 50 | 50 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 51 | 51 | |
| | 52 | import static org.junit.Assert.assertEquals; |
| | 53 | |
| 52 | 54 | /** |
| 53 | 55 | * Performance test of map renderer. |
| 54 | 56 | */ |
| … |
… |
public class MapRendererPerformanceTest {
|
| 99 | 101 | |
| 100 | 102 | img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB); |
| 101 | 103 | g = (Graphics2D) img.getGraphics(); |
| 102 | | g.setClip(0, 0, IMG_WIDTH, IMG_WIDTH); |
| | 104 | g.setClip(0, 0, IMG_WIDTH, IMG_HEIGHT); |
| 103 | 105 | g.setColor(Color.BLACK); |
| 104 | | g.fillRect(0, 0, IMG_WIDTH, IMG_WIDTH); |
| 105 | | nc = MainApplication.getMap().mapView; |
| 106 | | nc.setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT); |
| | 106 | g.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT); |
| | 107 | |
| | 108 | nc = new NavigatableComponent() { |
| | 109 | { |
| | 110 | setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT); |
| | 111 | updateLocationState(); |
| | 112 | } |
| | 113 | |
| | 114 | @Override |
| | 115 | protected boolean isVisibleOnScreen() { |
| | 116 | return true; |
| | 117 | } |
| | 118 | |
| | 119 | @Override |
| | 120 | public Point getLocationOnScreen() { |
| | 121 | return new Point(0, 0); |
| | 122 | } |
| | 123 | }; |
| | 124 | nc.zoomTo(BOUNDS_CITY_ALL); |
| 107 | 125 | |
| 108 | 126 | MapPaintStyles.readFromPreferences(); |
| 109 | 127 | |
| … |
… |
public class MapRendererPerformanceTest {
|
| 174 | 192 | public double scale = 0; |
| 175 | 193 | public LatLon center = LL_CITY; |
| 176 | 194 | public Bounds bounds; |
| 177 | | public int noWarmup = 3; |
| 178 | | public int noIterations = 7; |
| | 195 | public int noWarmup = 20; |
| | 196 | public int noIterations = 30; |
| 179 | 197 | public boolean dumpImage = DUMP_IMAGE; |
| 180 | 198 | public boolean clearStyleCache = true; |
| 181 | 199 | public String label = ""; |
| … |
… |
public class MapRendererPerformanceTest {
|
| 207 | 225 | } |
| 208 | 226 | |
| 209 | 227 | StyledMapRenderer renderer = new StyledMapRenderer(g, nc, false); |
| | 228 | assertEquals(IMG_WIDTH, (int) nc.getState().getViewWidth()); |
| | 229 | assertEquals(IMG_HEIGHT, (int) nc.getState().getViewHeight()); |
| 210 | 230 | |
| 211 | 231 | int noTotal = noWarmup + noIterations; |
| 212 | 232 | for (int i = 1; i <= noTotal; i++) { |
| 213 | 233 | g.setColor(Color.BLACK); |
| 214 | | g.fillRect(0, 0, IMG_WIDTH, IMG_WIDTH); |
| | 234 | g.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT); |
| 215 | 235 | if (clearStyleCache) { |
| 216 | 236 | MapPaintStyles.getStyles().clearCached(); |
| 217 | 237 | } |
| 218 | | System.gc(); |
| 219 | | System.runFinalization(); |
| 220 | | try { |
| 221 | | Thread.sleep(300); |
| 222 | | } catch (InterruptedException ex) { |
| 223 | | Logging.warn(ex); |
| 224 | | } |
| 225 | 238 | BenchmarkData data = new BenchmarkData(); |
| 226 | 239 | renderer.setBenchmarkFactory(() -> data); |
| 227 | 240 | renderer.render(dsCity, false, bounds); |
| … |
… |
public class MapRendererPerformanceTest {
|
| 233 | 246 | totalTimes.add(data.getGenerateTime() + data.getSortTime() + data.getDrawTime()); |
| 234 | 247 | } |
| 235 | 248 | if (i == 1) { |
| 236 | | dumpElementCount(data); |
| | 249 | data.dumpElementCount(); |
| 237 | 250 | } |
| 238 | 251 | dumpTimes(data); |
| 239 | 252 | if (dumpImage && i == noTotal) { |
| … |
… |
public class MapRendererPerformanceTest {
|
| 275 | 288 | test.bounds = BOUNDS_CITY_ALL; |
| 276 | 289 | test.label = "big"; |
| 277 | 290 | test.dumpImage = false; |
| 278 | | test.noWarmup = 3; |
| 279 | | test.noIterations = 10; |
| 280 | 291 | test.mpGenerate = true; |
| 281 | 292 | test.clearStyleCache = true; |
| 282 | 293 | test.run(); |
| … |
… |
public class MapRendererPerformanceTest {
|
| 284 | 295 | |
| 285 | 296 | private static void testDrawFeature(Feature feature) throws IOException { |
| 286 | 297 | PerformanceTester test = new PerformanceTester(); |
| 287 | | test.noWarmup = 3; |
| 288 | | test.noIterations = 10; |
| 289 | 298 | test.mpDraw = true; |
| 290 | 299 | test.clearStyleCache = false; |
| 291 | 300 | if (feature != null) { |
| … |
… |
public class MapRendererPerformanceTest {
|
| 301 | 310 | setFilterStyleActive(false); |
| 302 | 311 | } |
| 303 | 312 | MapPaintStyleLoader.reloadStyles(filterStyleIdx); |
| | 313 | dsCity.clearMappaintCache(); |
| 304 | 314 | test.run(); |
| 305 | 315 | } |
| 306 | 316 | |
| … |
… |
public class MapRendererPerformanceTest {
|
| 342 | 352 | } |
| 343 | 353 | |
| 344 | 354 | public static void dumpTimes(BenchmarkData bd) { |
| 345 | | System.out.print(String.format("gen. %3d, sort %3d, draw %3d%n", bd.getGenerateTime(), bd.getSortTime(), bd.getDrawTime())); |
| 346 | | } |
| 347 | | |
| 348 | | public static void dumpElementCount(BenchmarkData bd) { |
| 349 | | System.out.println(bd.recordElementStats().entrySet().stream() |
| 350 | | .map(e -> e.getKey().getSimpleName().replace("Element", "") + ":" + e.getValue()).collect(Collectors.joining(" "))); |
| | 355 | System.out.print(String.format("gen. %4d, sort %4d, draw %4d%n", bd.getGenerateTime(), bd.getSortTime(), bd.getDrawTime())); |
| 351 | 356 | } |
| 352 | 357 | |
| 353 | 358 | public static class BenchmarkData extends CapturingBenchmark { |
| … |
… |
public class MapRendererPerformanceTest {
|
| 372 | 377 | } |
| 373 | 378 | return styleElementCount; |
| 374 | 379 | } |
| | 380 | |
| | 381 | public void dumpElementCount() { |
| | 382 | System.out.println(recordElementStats().entrySet().stream() |
| | 383 | .sorted(Comparator.comparing(e -> e.getKey().getSimpleName())) |
| | 384 | .map(e -> e.getKey().getSimpleName().replace("Element", "") + ":" + e.getValue()) |
| | 385 | .collect(Collectors.joining(" "))); |
| | 386 | } |
| 375 | 387 | } |
| 376 | 388 | } |