source: josm/trunk/test/performance/org/openstreetmap/josm/data/osm/MapPaintVisitorPeformanceTest.java@ 3348

Last change on this file since 3348 was 3348, checked in by jttt, 14 years ago

Thread safe Dataset and OsmPrimitive, read/write lock for dataset

  • Property svn:mime-type set to text/plain
File size: 3.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.awt.Graphics2D;
5import java.awt.image.BufferedImage;
6import java.io.FileInputStream;
7
8import org.junit.BeforeClass;
9import org.junit.Test;
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.Bounds;
12import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintVisitor;
13import org.openstreetmap.josm.data.osm.visitor.paint.PaintVisitor;
14import org.openstreetmap.josm.data.projection.Mercator;
15import org.openstreetmap.josm.gui.NavigatableComponent;
16import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
17import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
18import org.openstreetmap.josm.io.OsmReader;
19
20public class MapPaintVisitorPeformanceTest {
21
22 private static final int IMG_WIDTH = 1400;
23 private static final int IMG_HEIGHT = 1050;
24
25 private static Graphics2D g;
26 private static BufferedImage img;
27 private static NavigatableComponent nc;
28 private static DataSet dsRestriction;
29 private static DataSet dsMultipolygon;
30 private static DataSet dsCity;
31
32 @BeforeClass
33 public static void load() throws Exception {
34 Main.proj = new Mercator();
35 img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
36 g = (Graphics2D)img.getGraphics();
37 nc = new NavigatableComponent();
38 nc.setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT);
39
40 // TODO Test should have it's own copy of styles because change in style can influence performance
41 Main.pref.load();
42 MapPaintStyles.readFromPreferences();
43
44 dsRestriction = OsmReader.parseDataSet(new FileInputStream("data_nodist/restriction.osm"), NullProgressMonitor.INSTANCE);
45 dsMultipolygon = OsmReader.parseDataSet(new FileInputStream("data_nodist/multipolygon.osm"), NullProgressMonitor.INSTANCE);
46 dsCity = OsmReader.parseDataSet(new FileInputStream("data_nodist/neubrandenburg.osm"), NullProgressMonitor.INSTANCE);
47
48 // Warm up
49 new MapPaintVisitorPeformanceTest().testRestrictionSmall();
50 new MapPaintVisitorPeformanceTest().testCity();
51 }
52
53 private static void test(int iterations, DataSet ds, Bounds bounds) throws Exception {
54 PaintVisitor visitor = new MapPaintVisitor();
55 nc.zoomTo(bounds);
56 visitor.setGraphics(g);
57 visitor.setNavigatableComponent(nc);
58 visitor.setInactive(false);
59 for (int i=0; i<iterations; i++) {
60 visitor.visitAll(ds, true, bounds);
61 }
62 }
63
64 @Test
65 public void testRestriction() throws Exception {
66 test(700, dsRestriction, new Bounds(51.12, 14.147472381591795, 51.128, 14.162492752075195));
67 }
68
69 @Test
70 public void testRestrictionSmall() throws Exception {
71 test(1500, dsRestriction, new Bounds(51.125, 14.147, 51.128, 14.152));
72 }
73
74 @Test
75 public void testMultipolygon() throws Exception {
76 test(400, dsMultipolygon, new Bounds(60, -180, 85, -122));
77 }
78
79 @Test
80 public void testMultipolygonSmall() throws Exception {
81 test(850, dsMultipolygon, new Bounds(-90, -180, 90, 180));
82 }
83
84 @Test
85 public void testCity() throws Exception {
86 test(50, dsCity, new Bounds(53.51, 13.20, 53.59, 13.34));
87 }
88
89 @Test
90 public void testCitySmall() throws Exception {
91 test(70, dsCity, new Bounds(52, 11, 55, 14));
92 }
93
94 @Test
95 public void testCityPart1() throws Exception {
96 test(250, dsCity, new Bounds(53.56, 13.25, 53.57, 13.26));
97 }
98
99 @Test
100 public void testCityPart2() throws Exception {
101 test(200, dsCity, new Bounds(53.55, 13.29, 53.57, 13.30));
102 }
103
104 @Test
105 public void testCitySmallPart2() throws Exception {
106 test(200, dsCity, new Bounds(53.56, 13.295, 53.57, 13.30));
107 }
108
109
110
111}
Note: See TracBrowser for help on using the repository browser.