Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertTrue;
|
---|
5 |
|
---|
6 | import org.junit.Test;
|
---|
7 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
8 | import org.openstreetmap.josm.data.coor.LatLonTest;
|
---|
9 |
|
---|
10 | public 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.