Skip to content

Commit

Permalink
update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
delfrrr committed Sep 19, 2018
1 parent 0b0e69d commit d5cc9f4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScr
## Features

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

## Usage
Expand Down Expand Up @@ -44,3 +43,21 @@ int main() {
```

[See more examples here](./examples)

## Benchmarks

```
Run on (4 X 2300 MHz CPU s)
2018-09-19 09:40:29
------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------
BM_45K_geojson_nodes 23 ms 23 ms 32
BM_2K_uniform 1 ms 1 ms 970
BM_100K_uniform 63 ms 63 ms 10
BM_200K_uniform 142 ms 141 ms 4
BM_500K_uniform 415 ms 412 ms 2
BM_1M_uniform 1016 ms 1010 ms 1
```

Library is ~10% faster then JS version for 1M uniform points ([details](https://github.com/delfrrr/delaunator-cpp/pull/8#issuecomment-422690056))
32 changes: 28 additions & 4 deletions bench/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
#include <string>
#include <vector>

namespace {
std::vector<double> generate_uniform(size_t n) {
std::vector<double> coords;
std::srand(350);

double norm = static_cast<double>(RAND_MAX) / 1e3;
for (size_t i = 0; i < n; i++) {
coords.push_back(double(std::rand()) / RAND_MAX);
coords.push_back(double(std::rand()) / RAND_MAX);
coords.push_back(static_cast<double>(std::rand()) / norm);
coords.push_back(static_cast<double>(std::rand()) / norm);
}

return coords;
}

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

void BM_2K_uniform(benchmark::State& state) {
std::vector<double> coords = generate_uniform(2000);
while (state.KeepRunning()) {
delaunator::Delaunator delaunator(coords);
}
}

void BM_100K_uniform(benchmark::State& state) {
std::vector<double> coords = generate_uniform(100000);
while (state.KeepRunning()) {
delaunator::Delaunator delaunator(coords);
}
}

void BM_200K_uniform(benchmark::State& state) {
std::vector<double> coords = generate_uniform(200000);
while (state.KeepRunning()) {
delaunator::Delaunator delaunator(coords);
}
}

void BM_500K_uniform(benchmark::State& state) {
std::vector<double> coords = generate_uniform(500000);
while (state.KeepRunning()) {
delaunator::Delaunator delaunator(coords);
}
}

void BM_1M_uniform(benchmark::State& state) {
std::vector<double> coords = generate_uniform(1000000);
while (state.KeepRunning()) {
Expand All @@ -43,7 +64,10 @@ void BM_1M_uniform(benchmark::State& state) {
} // namespace

BENCHMARK(BM_45K_geojson_nodes)->Unit(benchmark::kMillisecond);
BENCHMARK(BM_2K_uniform)->Unit(benchmark::kMillisecond);
BENCHMARK(BM_100K_uniform)->Unit(benchmark::kMillisecond);
BENCHMARK(BM_200K_uniform)->Unit(benchmark::kMillisecond);
BENCHMARK(BM_500K_uniform)->Unit(benchmark::kMillisecond);
BENCHMARK(BM_1M_uniform)->Unit(benchmark::kMillisecond);

BENCHMARK_MAIN()

0 comments on commit d5cc9f4

Please sign in to comment.