Changeset 12650 in josm for trunk/test/performance/org/openstreetmap
- Timestamp:
- 2017-08-25T22:25:25+02:00 (7 years ago)
- Location:
- trunk/test/performance/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/performance/org/openstreetmap/josm/gui/mappaint/MapRendererPerformanceTest.java
r12649 r12650 308 308 } 309 309 310 /** 311 * Resets MapPaintStyles to a single source. 312 * @param source new map paint style source 313 */ 314 public static void resetStylesToSingle(StyleSource source) { 315 MapPaintStyles.getStyles().clear(); 316 MapPaintStyles.getStyles().add(source); 317 } 318 310 319 private static void setFilterStyleActive(boolean active) { 311 320 if (filterStyle.active != active) { -
trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSPerformanceTest.java
r12649 r12650 2 2 package org.openstreetmap.josm.gui.mappaint.mapcss; 3 3 4 import static org.junit.Assert. *4 import static org.junit.Assert.fail; 5 5 6 import java.awt.Graphics2D 7 import java.awt.image.BufferedImage 6 import java.awt.Graphics2D; 7 import java.awt.image.BufferedImage; 8 import java.io.File; 9 import java.io.IOException; 10 import java.util.Collection; 8 11 9 import org.junit.* 10 import org.openstreetmap.josm.JOSMFixture 11 import org.openstreetmap.josm.data.Bounds 12 import org.openstreetmap.josm.data.osm.DataSet 13 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer 14 import org.openstreetmap.josm.gui.NavigatableComponent 15 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles 16 import org.openstreetmap.josm.gui.preferences.SourceEntry 17 import org.openstreetmap.josm.io.Compression 18 import org.openstreetmap.josm.io.OsmReader 12 import org.junit.BeforeClass; 13 import org.junit.Test; 14 import org.openstreetmap.josm.JOSMFixture; 15 import org.openstreetmap.josm.data.Bounds; 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 18 import org.openstreetmap.josm.data.preferences.sources.SourceEntry; 19 import org.openstreetmap.josm.gui.NavigatableComponent; 20 import org.openstreetmap.josm.gui.mappaint.MapRendererPerformanceTest; 21 import org.openstreetmap.josm.io.Compression; 22 import org.openstreetmap.josm.io.IllegalDataException; 23 import org.openstreetmap.josm.io.OsmReader; 19 24 20 25 /** … … 23 28 * 24 29 */ 25 class MapCSSPerformanceTest {30 public class MapCSSPerformanceTest { 26 31 27 32 /* ------------------------ configuration section ---------------------------- */ … … 29 34 * The path to the style file used for rendering. 30 35 */ 31 def static STYLE_FILE="styles/standard/elemstyles.mapcss"36 static final String STYLE_FILE = "styles/standard/elemstyles.mapcss"; 32 37 33 38 /** 34 39 * The data file to be rendered 35 40 */ 36 def static DATA_FILE = "data_nodist/neubrandenburg.osm.bz2"41 static final String DATA_FILE = "data_nodist/neubrandenburg.osm.bz2"; 37 42 /* ------------------------ / configuration section ---------------------------- */ 38 43 39 def DataSet ds44 DataSet ds; 40 45 41 def static booleancheckTestEnvironment() {46 static void checkTestEnvironment() { 42 47 File f = new File(STYLE_FILE); 43 if ( !f.isFile() || ! f.exists()) { 44 fail("STYLE_FILE refers to '${STYLE_FILE}. This is either not a file or doesn't exist.\nPlease update configuration settings in the unit test file.") 48 if (!f.isFile() || !f.exists()) { 49 fail("STYLE_FILE refers to '"+STYLE_FILE+"'. This is either not a file or doesn't exist.\n" + 50 "Please update configuration settings in the unit test file."); 45 51 } 46 52 } 47 53 54 /** 55 * Setup test. 56 */ 48 57 @BeforeClass 49 58 public static void createJOSMFixture() { … … 51 60 } 52 61 53 def timed(Closure c){54 long before = System.currentTimeMillis() 55 c ()56 long after = System.currentTimeMillis() 57 return after - before 62 long timed(Runnable callable) { 63 long before = System.currentTimeMillis(); 64 callable.run(); 65 long after = System.currentTimeMillis(); 66 return after - before; 58 67 } 59 68 60 defloadStyle() {61 print "Loading style '$STYLE_FILE' ..."69 void loadStyle() { 70 System.out.println("Loading style '"+STYLE_FILE+"' ..."); 62 71 MapCSSStyleSource source = new MapCSSStyleSource( 63 72 new SourceEntry( … … 67 76 true // active 68 77 ) 69 ) 70 source.loadStyleSource() 71 if (!source.errors.isEmpty()) { 72 fail("Failed to load style file ''${STYLE_FILE}''. Errors: ${source.errors}") 78 ); 79 source.loadStyleSource(); 80 Collection<Throwable> errors = source.getErrors(); 81 if (!errors.isEmpty()) { 82 fail("Failed to load style file ''"+STYLE_FILE+"''. Errors: "+errors); 73 83 } 74 MapPaintStyles.getStyles().clear() 75 MapPaintStyles.getStyles().add(source) 76 println "DONE" 84 MapRendererPerformanceTest.resetStylesToSingle(source); 85 System.out.println("DONE"); 77 86 } 78 87 79 def loadData(){80 print "Loading data file '$DATA_FILE' ..."88 void loadData() throws IllegalDataException, IOException { 89 System.out.print("Loading data file '"+DATA_FILE+"' ..."); 81 90 ds = OsmReader.parseDataSet(Compression.getUncompressedFileInputStream(new File(DATA_FILE)), null); 82 println "DONE"91 System.out.println("DONE"); 83 92 } 84 93 94 /** 95 * Measures time for style preparation. 96 * @throws IOException if any I/O error occurs 97 * @throws IllegalDataException if any invalid data is found 98 */ 85 99 @Test 86 public void measureTimeForStylePreparation() {87 loadStyle() 88 loadData() 100 public void measureTimeForStylePreparation() throws IllegalDataException, IOException { 101 loadStyle(); 102 loadData(); 89 103 90 104 NavigatableComponent mv = new NavigatableComponent(); 91 mv.setBounds(0, 0, 1024, 768) 92 BufferedImage img = new BufferedImage(mv.getWidth(), mv.getHeight(), BufferedImage.TYPE_3BYTE_BGR) 93 Graphics2D g = img.createGraphics() 94 g.setClip(0, 0, mv.getWidth(), mv.getHeight())95 StyledMapRenderer visitor = new StyledMapRenderer(g, mv, false) 105 mv.setBounds(0, 0, 1024, 768); 106 BufferedImage img = new BufferedImage(mv.getWidth(), mv.getHeight(), BufferedImage.TYPE_3BYTE_BGR); 107 Graphics2D g = img.createGraphics(); 108 g.setClip(0, 0, mv.getWidth(), mv.getHeight()); 109 StyledMapRenderer visitor = new StyledMapRenderer(g, mv, false); 96 110 97 print "Rendering ..."98 long time = timed {99 visitor.render(ds, false, new Bounds(-90,-180,90,180))100 }101 println "DONE"102 println "data file : ${DATA_FILE}"103 println "style file: ${STYLE_FILE}"104 println ""105 println "Rendering took $time ms."111 System.out.print("Rendering ..."); 112 long time = timed( 113 () -> visitor.render(ds, false, new Bounds(-90, -180, 90, 180)) 114 ); 115 System.out.println("DONE"); 116 System.out.println("data file : "+DATA_FILE); 117 System.out.println("style file: "+STYLE_FILE); 118 System.out.println(""); 119 System.out.println("Rendering took "+time+" ms."); 106 120 } 107 121 }
Note:
See TracChangeset
for help on using the changeset viewer.