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

Last change on this file since 7068 was 7068, checked in by Don-vip, 10 years ago

test cleanup

File size: 1.3 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
10public class RoundingPerformanceTest {
11
12 private static double oldRoundToOsmPrecision(double value) {
13 return Math.round(value / LatLon.MAX_SERVER_PRECISION) * LatLon.MAX_SERVER_PRECISION; // Old method, causes rounding errors, but efficient
14 }
15
16 @Test
17 public void test() {
18 final int n = 1000000;
19 long start = System.nanoTime();
20 for (int i = 0; i < n; i++) {
21 for (double value : LatLonTest.SAMPLE_VALUES) {
22 oldRoundToOsmPrecision(value);
23 }
24 }
25 long end = System.nanoTime();
26 long oldTime = end-start;
27 System.out.println("Old time: "+oldTime/1000000.0 + " ms");
28
29 start = System.nanoTime();
30 for (int i = 0; i < n; i++) {
31 for (double value : LatLonTest.SAMPLE_VALUES) {
32 LatLon.roundToOsmPrecision(value);
33 }
34 }
35 end = System.nanoTime();
36 long newTime = end-start;
37 System.out.println("New time: "+newTime/1000000.0 + " ms");
38
39 assertTrue(newTime <= oldTime*10);
40 }
41}
Note: See TracBrowser for help on using the repository browser.