From 05034481c37bd26dfbdbd9f5ab78f7ad5629a3e2 Mon Sep 17 00:00:00 2001 From: Lene Preuss Date: Wed, 13 Oct 2021 12:48:50 +0200 Subject: [PATCH] added test which times the runtime of decoding a long polyline Signed-off-by: Lene Preuss --- .../PolylineEncoderDecoderTest.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/java/src/com/here/flexpolyline/PolylineEncoderDecoderTest.java b/java/src/com/here/flexpolyline/PolylineEncoderDecoderTest.java index 6d19a44..bbbc347 100644 --- a/java/src/com/here/flexpolyline/PolylineEncoderDecoderTest.java +++ b/java/src/com/here/flexpolyline/PolylineEncoderDecoderTest.java @@ -19,6 +19,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -130,7 +131,6 @@ private void testThirdDimension() { assertTrue(getThirdDimension("B1Boz5xJ67i1BU") == ELEVATION); } - private void testDecodeConvertValue() { String encoded = "h_wqiB"; @@ -284,6 +284,21 @@ private void decodingSmokeTest() { } } + private void testVeryLongLine(int lineLength) { + final int PRECISION = 10; + Random random = new Random(); + List coordinates = new ArrayList(); + for (int i = 0; i <= lineLength; i++) { + LatLngZ nextPoint = new LatLngZ(random.nextDouble(), random.nextDouble(), random.nextDouble()); + coordinates.add(nextPoint); + } + String encoded = encode(coordinates, PRECISION, ThirdDimension.ALTITUDE, PRECISION); + long startTime = System.nanoTime(); + List decoded = decode(encoded); + long duration = (System.nanoTime() - startTime); + System.out.println("duration: " + duration/1000 + "us"); + } + private static List extractLatLngZ(String line, boolean hasThirdDimension) { List latLngZs = new ArrayList(); @@ -335,6 +350,12 @@ private static void assertThrows(Class expectedType, Ru } public static void main(String[] args) { + final int DEFAULT_LINE_LENGTH = 100000; + int lineLength = DEFAULT_LINE_LENGTH; + if (args.length > 0) { + lineLength = Integer.parseInt(args[0]); + } + PolylineEncoderDecoderTest test = new PolylineEncoderDecoderTest(); test.testInvalidCoordinates(); test.testInvalidThirdDimension(); @@ -352,5 +373,7 @@ public static void main(String[] args) { test.testComplexLatLngDecoding(); test.testLatLngZDecode(); test.decodingSmokeTest(); + + test.testVeryLongLine(lineLength); } }