diff --git a/README.md b/README.md index 1d06e17..affae86 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ ## Installation `pip install pypolyline` -Please use a recent (>= 8.1.2) version of `pip`. ### Supported Python Versions - Python 3.8 @@ -48,7 +47,7 @@ FFI and a [Rust binary](https://github.com/urschrei/polyline-ffi) ## Is It Fast …Yes. You can verify this by installing the `polyline` package, then running [`benchmarks.py`](benchmarks.py), a calibrated benchmark using `cProfile`. -On a 1.8 GHz Intel Core i7, The pure-Python test runs in ~5000 ms and The Rust + Cython benchmark runs in around 300 ms (177 % faster). +On an M2 MBP, The [pure-Python](https://pypi.org/project/polyline/) test runs in ~2500 ms, the [Flexpolyline](https://pypi.org/project/flexpolyline/) benchmark runs in ~1500 ms and The Rust + Cython benchmark runs in around 80 ms (30 x and 17.5 x faster, respectively). ## License [MIT](license.txt) diff --git a/benches/benchmark_flexpolyline.py b/benches/benchmark_flexpolyline.py new file mode 100644 index 0000000..8b545f2 --- /dev/null +++ b/benches/benchmark_flexpolyline.py @@ -0,0 +1,17 @@ +import flexpolyline as fp +import numpy as np + +# London bounding box +N = 51.691874116909894 +E = 0.3340155643740321 +S = 51.28676016315085 +W = -0.5103750689005356 + +num_coords = 1000 +coords = list( + zip(np.random.uniform(S, N, [num_coords]), np.random.uniform(W, E, [num_coords])) +) + +if __name__ == "__main__": + for x in range(500): + fp.encode(coords, precision=5) diff --git a/benchmarks.py b/benchmarks.py index 874f66e..cf2ea5e 100644 --- a/benchmarks.py +++ b/benchmarks.py @@ -4,11 +4,12 @@ """ import cProfile -import pstats import profile +import pstats + import numpy as np -print("Running Rust, Python, and C++ benchmarks. 1000 points, 500 runs.\n") +print("Running Rust, Python, and Flexpolyline benchmarks. 1000 points, 500 runs.\n") # calibrate print("Calibrating system") @@ -18,16 +19,21 @@ profile.Profile.bias = calibration print("Calibration complete, running benchmarks\n") bmarks = [ - ('benches/benchmark_rust.py', 'benches/output_stats_rust', 'Rust + Cython'), - ('benches/benchmark_python.py', 'benches/output_stats_python', 'Pure Python'), + ("benches/benchmark_rust.py", "benches/output_stats_rust", "Rust + Cython"), + ("benches/benchmark_python.py", "benches/output_stats_python", "Pure Python"), + ( + "benches/benchmark_flexpolyline.py", + "benches/output_stats_flexpolyline", + "Python Flexpolyline", + ), ] results = [] for benchmark in bmarks: - with open(benchmark[0], 'rb') as f: + with open(benchmark[0], "rb") as f: cProfile.run(f.read(), benchmark[1]) results.append(pstats.Stats(benchmark[1])) for i, benchmark in enumerate(bmarks): print("%s Benchmark\n" % benchmark[2]) - results[i].sort_stats('cumulative').print_stats(3) + results[i].sort_stats("cumulative").print_stats(3)