Changeset 12650 in josm


Ignore:
Timestamp:
2017-08-25T22:25:25+02:00 (3 months ago)
Author:
Don-vip
Message:

see #15182 - convert MapCSS performance test to Java + update import

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  
    308308    }
    309309
     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
    310319    private static void setFilterStyleActive(boolean active) {
    311320        if (filterStyle.active != active) {
  • trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSPerformanceTest.java

    r12649 r12650  
    22package org.openstreetmap.josm.gui.mappaint.mapcss;
    33
    4 import static org.junit.Assert.*
     4import static org.junit.Assert.fail;
    55
    6 import java.awt.Graphics2D
    7 import java.awt.image.BufferedImage
     6import java.awt.Graphics2D;
     7import java.awt.image.BufferedImage;
     8import java.io.File;
     9import java.io.IOException;
     10import java.util.Collection;
    811
    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
     12import org.junit.BeforeClass;
     13import org.junit.Test;
     14import org.openstreetmap.josm.JOSMFixture;
     15import org.openstreetmap.josm.data.Bounds;
     16import org.openstreetmap.josm.data.osm.DataSet;
     17import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
     18import org.openstreetmap.josm.data.preferences.sources.SourceEntry;
     19import org.openstreetmap.josm.gui.NavigatableComponent;
     20import org.openstreetmap.josm.gui.mappaint.MapRendererPerformanceTest;
     21import org.openstreetmap.josm.io.Compression;
     22import org.openstreetmap.josm.io.IllegalDataException;
     23import org.openstreetmap.josm.io.OsmReader;
    1924
    2025/**
     
    2328 *
    2429 */
    25 class MapCSSPerformanceTest {
     30public class MapCSSPerformanceTest {
    2631
    2732    /* ------------------------ configuration section  ---------------------------- */
     
    2934     * The path to the style file used for rendering.
    3035     */
    31     def static STYLE_FILE="styles/standard/elemstyles.mapcss"
     36    static final String STYLE_FILE = "styles/standard/elemstyles.mapcss";
    3237
    3338    /**
    3439     * The data file to be rendered
    3540     */
    36     def static DATA_FILE = "data_nodist/neubrandenburg.osm.bz2"
     41    static final String DATA_FILE = "data_nodist/neubrandenburg.osm.bz2";
    3742    /* ------------------------ / configuration section  ---------------------------- */
    3843
    39     def DataSet ds
     44    DataSet ds;
    4045
    41     def static boolean checkTestEnvironment() {
     46    static void checkTestEnvironment() {
    4247          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.");
    4551          }
    4652    }
    4753
     54    /**
     55     * Setup test.
     56     */
    4857    @BeforeClass
    4958    public static void createJOSMFixture() {
     
    5160    }
    5261
    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;
    5867    }
    5968
    60     def loadStyle() {
    61         print "Loading style '$STYLE_FILE' ..."
     69    void loadStyle() {
     70        System.out.println("Loading style '"+STYLE_FILE+"' ...");
    6271        MapCSSStyleSource source = new MapCSSStyleSource(
    6372            new SourceEntry(
     
    6776                true // active
    6877            )
    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);
    7383        }
    74         MapPaintStyles.getStyles().clear()
    75         MapPaintStyles.getStyles().add(source)
    76         println "DONE"
     84        MapRendererPerformanceTest.resetStylesToSingle(source);
     85        System.out.println("DONE");
    7786    }
    7887
    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+"' ...");
    8190        ds = OsmReader.parseDataSet(Compression.getUncompressedFileInputStream(new File(DATA_FILE)), null);
    82         println "DONE"
     91        System.out.println("DONE");
    8392    }
    8493
     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     */
    8599    @Test
    86     public void measureTimeForStylePreparation() {
    87         loadStyle()
    88         loadData()
     100    public void measureTimeForStylePreparation() throws IllegalDataException, IOException {
     101        loadStyle();
     102        loadData();
    89103
    90104        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);
    96110
    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.");
    106120    }
    107121}
Note: See TracChangeset for help on using the changeset viewer.