Skip to content

Commit

Permalink
Update benchmarks and README
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed May 13, 2024
1 parent 839ba02 commit 744d58b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

## Installation
`pip install pypolyline`
Please use a recent (>= 8.1.2) version of `pip`.

### Supported Python Versions
- Python 3.8
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions benches/benchmark_flexpolyline.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 12 additions & 6 deletions benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

0 comments on commit 744d58b

Please sign in to comment.