From 9559db9ea1eb4c5d7a443759ef976893eb1fb4c9 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sat, 11 May 2024 13:48:32 -0700 Subject: [PATCH] Skip intermediate coord representation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can just build up the coords directly rather than building up arrays and then converting them to Coords. ``` $ cargo bench --bench="*" -- --baseline=sha-6872788 Compiling polyline v0.10.2 (/Users/mkirk/src/georust/polyline) Finished `bench` profile [optimized] target(s) in 0.94s Running benches/benchmarks.rs (target/release/deps/benchmarks-8b91c88197106af3) encode 10_000 coordinates at precision 1e-5 time: [180.56 µs 180.85 µs 181.16 µs] change: [-1.3886% -1.0790% -0.7773%] (p = 0.00 < 0.05) Change within noise threshold. Found 5 outliers among 100 measurements (5.00%) 2 (2.00%) low mild 3 (3.00%) high mild encode 10_000 coordinates at precision 1e-6 time: [219.72 µs 220.82 µs 221.84 µs] change: [+0.5301% +1.0508% +1.5979%] (p = 0.00 < 0.05) Change within noise threshold. decode 10_000 coordinates at precision 1e-5 time: [80.937 µs 81.828 µs 82.713 µs] change: [-4.9284% -3.9764% -2.9753%] (p = 0.00 < 0.05) Performance has improved. decode 10_000 coordinates at precision 1e-6 time: [97.706 µs 98.786 µs 99.825 µs] change: [-3.1947% -2.2649% -1.3617%] (p = 0.00 < 0.05) Performance has improved. ``` --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 82c4b36..f9d3c5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -146,10 +146,10 @@ pub fn decode_polyline(polyline: &str, precision: u32) -> Result }); } - coordinates.push([lon, lat]); + coordinates.push(Coord { x: lon, y: lat }); } - Ok(coordinates.into()) + Ok(LineString::new(coordinates)) } fn decode_next(