source: josm/trunk/test/performance/org/openstreetmap/josm/data/osm/RoundingPerformanceTest.java@ 8632

Last change on this file since 8632 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import static org.junit.Assert.assertTrue;
5
6import org.junit.Test;
7import org.openstreetmap.josm.data.coor.LatLon;
8import org.openstreetmap.josm.data.coor.LatLonTest;
9
10/**
11 * Checks that rounding of coordinates is not too slow.
12 */
13public class RoundingPerformanceTest {
14
15 private static double oldRoundToOsmPrecision(double value) {
16 // Old method, causes rounding errors, but efficient
17 return Math.round(value / LatLon.MAX_SERVER_PRECISION) * LatLon.MAX_SERVER_PRECISION;
18 }
19
20 /**
21 * Checks that rounding of coordinates is not too slow.
22 */
23 @Test
24 public void test() {
25 final int n = 1000000;
26 long start = System.nanoTime();
27 for (int i = 0; i < n; i++) {
28 for (double value : LatLonTest.SAMPLE_VALUES) {
29 oldRoundToOsmPrecision(value);
30 }
31 }
32 long end = System.nanoTime();
33 long oldTime = end-start;
34 System.out.println("Old time: "+oldTime/1000000.0 + " ms");
35
36 start = System.nanoTime();
37 for (int i = 0; i < n; i++) {
38 for (double value : LatLonTest.SAMPLE_VALUES) {
39 LatLon.roundToOsmPrecision(value);
40 }
41 }
42 end = System.nanoTime();
43 long newTime = end-start;
44 System.out.println("New time: "+newTime/1000000.0 + " ms");
45
46 assertTrue(newTime <= oldTime*12);
47 }
48}
Note: See TracBrowser for help on using the repository browser.