Skip to content

Commit d5cc9f4

Browse files
committed
update benchmarks
1 parent 0b0e69d commit d5cc9f4

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScr
1111
## Features
1212

1313
* Probably the fastest C++ open source 2D Delaunay implementation
14-
* Roughly 6 times faster then JS version `[email protected]` ([needs confirmation](https://github.com/delfrrr/delaunator-cpp/pull/8))
1514
* Example showing triangulation of GeoJson points
1615

1716
## Usage
@@ -44,3 +43,21 @@ int main() {
4443
```
4544

4645
[See more examples here](./examples)
46+
47+
## Benchmarks
48+
49+
```
50+
Run on (4 X 2300 MHz CPU s)
51+
2018-09-19 09:40:29
52+
------------------------------------------------------------
53+
Benchmark Time CPU Iterations
54+
------------------------------------------------------------
55+
BM_45K_geojson_nodes 23 ms 23 ms 32
56+
BM_2K_uniform 1 ms 1 ms 970
57+
BM_100K_uniform 63 ms 63 ms 10
58+
BM_200K_uniform 142 ms 141 ms 4
59+
BM_500K_uniform 415 ms 412 ms 2
60+
BM_1M_uniform 1016 ms 1010 ms 1
61+
```
62+
63+
Library is ~10% faster then JS version for 1M uniform points ([details](https://github.com/delfrrr/delaunator-cpp/pull/8#issuecomment-422690056))

bench/run.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
#include <string>
66
#include <vector>
77

8+
namespace {
89
std::vector<double> generate_uniform(size_t n) {
910
std::vector<double> coords;
1011
std::srand(350);
11-
12+
double norm = static_cast<double>(RAND_MAX) / 1e3;
1213
for (size_t i = 0; i < n; i++) {
13-
coords.push_back(double(std::rand()) / RAND_MAX);
14-
coords.push_back(double(std::rand()) / RAND_MAX);
14+
coords.push_back(static_cast<double>(std::rand()) / norm);
15+
coords.push_back(static_cast<double>(std::rand()) / norm);
1516
}
1617

1718
return coords;
1819
}
1920

20-
namespace {
2121
void BM_45K_geojson_nodes(benchmark::State& state) {
2222
std::string points_str = utils::read_file("./test/test-files/osm-nodes-45331-epsg-3857.geojson");
2323
std::vector<double> coords = utils::get_geo_json_points(points_str);
@@ -27,13 +27,34 @@ void BM_45K_geojson_nodes(benchmark::State& state) {
2727
}
2828
}
2929

30+
void BM_2K_uniform(benchmark::State& state) {
31+
std::vector<double> coords = generate_uniform(2000);
32+
while (state.KeepRunning()) {
33+
delaunator::Delaunator delaunator(coords);
34+
}
35+
}
36+
3037
void BM_100K_uniform(benchmark::State& state) {
3138
std::vector<double> coords = generate_uniform(100000);
3239
while (state.KeepRunning()) {
3340
delaunator::Delaunator delaunator(coords);
3441
}
3542
}
3643

44+
void BM_200K_uniform(benchmark::State& state) {
45+
std::vector<double> coords = generate_uniform(200000);
46+
while (state.KeepRunning()) {
47+
delaunator::Delaunator delaunator(coords);
48+
}
49+
}
50+
51+
void BM_500K_uniform(benchmark::State& state) {
52+
std::vector<double> coords = generate_uniform(500000);
53+
while (state.KeepRunning()) {
54+
delaunator::Delaunator delaunator(coords);
55+
}
56+
}
57+
3758
void BM_1M_uniform(benchmark::State& state) {
3859
std::vector<double> coords = generate_uniform(1000000);
3960
while (state.KeepRunning()) {
@@ -43,7 +64,10 @@ void BM_1M_uniform(benchmark::State& state) {
4364
} // namespace
4465

4566
BENCHMARK(BM_45K_geojson_nodes)->Unit(benchmark::kMillisecond);
67+
BENCHMARK(BM_2K_uniform)->Unit(benchmark::kMillisecond);
4668
BENCHMARK(BM_100K_uniform)->Unit(benchmark::kMillisecond);
69+
BENCHMARK(BM_200K_uniform)->Unit(benchmark::kMillisecond);
70+
BENCHMARK(BM_500K_uniform)->Unit(benchmark::kMillisecond);
4771
BENCHMARK(BM_1M_uniform)->Unit(benchmark::kMillisecond);
4872

4973
BENCHMARK_MAIN()

0 commit comments

Comments
 (0)