Changeset 16542 in josm for trunk/test
- Timestamp:
- 2020-06-07T09:46:52+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/performance/org/openstreetmap/josm/gui/mappaint/MapRendererPerformanceTest.java
r16519 r16542 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; … … 10 11 import java.util.ArrayList; 11 12 import java.util.Collections; 13 import java.util.Comparator; 12 14 import java.util.EnumMap; 13 import java.util.HashMap;14 15 import java.util.List; 15 16 import java.util.Locale; … … 35 36 import org.openstreetmap.josm.data.preferences.sources.SourceEntry; 36 37 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 37 import org.openstreetmap.josm.gui.MainApplication;38 38 import org.openstreetmap.josm.gui.NavigatableComponent; 39 39 import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting; … … 46 46 import org.openstreetmap.josm.io.OsmReader; 47 47 import org.openstreetmap.josm.testutils.JOSMTestRules; 48 import org.openstreetmap.josm.tools.Logging;49 48 50 49 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 50 51 import static org.junit.Assert.assertEquals; 51 52 52 53 /** … … 100 101 img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB); 101 102 g = (Graphics2D) img.getGraphics(); 102 g.setClip(0, 0, IMG_WIDTH, IMG_ WIDTH);103 g.setClip(0, 0, IMG_WIDTH, IMG_HEIGHT); 103 104 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); 105 g.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT); 106 107 nc = new NavigatableComponent() { 108 { 109 setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT); 110 updateLocationState(); 111 } 112 113 @Override 114 protected boolean isVisibleOnScreen() { 115 return true; 116 } 117 118 @Override 119 public Point getLocationOnScreen() { 120 return new Point(0, 0); 121 } 122 }; 123 nc.zoomTo(BOUNDS_CITY_ALL); 107 124 108 125 MapPaintStyles.readFromPreferences(); … … 175 192 public LatLon center = LL_CITY; 176 193 public Bounds bounds; 177 public int noWarmup = 3;178 public int noIterations = 7;194 public int noWarmup = 20; 195 public int noIterations = 30; 179 196 public boolean dumpImage = DUMP_IMAGE; 180 197 public boolean clearStyleCache = true; … … 208 225 209 226 StyledMapRenderer renderer = new StyledMapRenderer(g, nc, false); 227 assertEquals(IMG_WIDTH, (int) nc.getState().getViewWidth()); 228 assertEquals(IMG_HEIGHT, (int) nc.getState().getViewHeight()); 210 229 211 230 int noTotal = noWarmup + noIterations; 212 231 for (int i = 1; i <= noTotal; i++) { 213 232 g.setColor(Color.BLACK); 214 g.fillRect(0, 0, IMG_WIDTH, IMG_ WIDTH);233 g.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT); 215 234 if (clearStyleCache) { 216 235 MapPaintStyles.getStyles().clearCached(); 217 }218 System.gc();219 System.runFinalization();220 try {221 Thread.sleep(300);222 } catch (InterruptedException ex) {223 Logging.warn(ex);224 236 } 225 237 BenchmarkData data = new BenchmarkData(); … … 234 246 } 235 247 if (i == 1) { 236 d umpElementCount(data);237 } 238 d umpTimes(data);248 data.dumpElementCount(); 249 } 250 data.dumpTimes(); 239 251 if (dumpImage && i == noTotal) { 240 252 dumpRenderedImage(label); … … 276 288 test.label = "big"; 277 289 test.dumpImage = false; 278 test.noWarmup = 3;279 test.noIterations = 10;280 290 test.mpGenerate = true; 281 291 test.clearStyleCache = true; … … 285 295 private static void testDrawFeature(Feature feature) throws IOException { 286 296 PerformanceTester test = new PerformanceTester(); 287 test.noWarmup = 3;288 test.noIterations = 10;289 297 test.mpDraw = true; 290 298 test.clearStyleCache = false; … … 302 310 } 303 311 MapPaintStyleLoader.reloadStyles(filterStyleIdx); 312 dsCity.clearMappaintCache(); 304 313 test.run(); 305 314 } … … 333 342 MapPaintStyles.toggleStyleActive(filterStyleIdx); 334 343 } 335 Assert.assertEquals(active, filterStyle.active);344 // Assert.assertEquals(active, filterStyle.active); 336 345 } 337 346 } … … 340 349 File outputfile = new File("test-neubrandenburg-"+id+".png"); 341 350 ImageIO.write(img, "png", outputfile); 342 }343 344 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(" ")));351 351 } 352 352 … … 361 361 } 362 362 363 private Map<Class<? extends StyleElement>, Integer> recordElementStats() { 364 Map<Class<? extends StyleElement>, Integer> styleElementCount = new HashMap<>(); 365 for (StyleRecord r : allStyleElems) { 366 Class<? extends StyleElement> klass = r.getStyle().getClass(); 367 Integer count = styleElementCount.get(klass); 368 if (count == null) { 369 count = 0; 370 } 371 styleElementCount.put(klass, count + 1); 372 } 373 return styleElementCount; 363 private Map<Class<? extends StyleElement>, Long> recordElementStats() { 364 return allStyleElems.stream() 365 .collect(Collectors.groupingBy(r -> r.getStyle().getClass(), Collectors.counting())); 366 } 367 368 public void dumpTimes() { 369 System.out.print(String.format("gen. %4d, sort %4d, draw %4d%n", getGenerateTime(), getSortTime(), getDrawTime())); 370 } 371 372 public void dumpElementCount() { 373 System.out.println(recordElementStats().entrySet().stream() 374 .sorted(Comparator.comparing(e -> e.getKey().getSimpleName())) 375 .map(e -> e.getKey().getSimpleName().replace("Element", "") + ":" + e.getValue()) 376 .collect(Collectors.joining(" "))); 374 377 } 375 378 }
Note:
See TracChangeset
for help on using the changeset viewer.