update benchmarks
diff --git a/README.md b/README.md index dca650a..67b6a49 100644 --- a/README.md +++ b/README.md
@@ -11,7 +11,6 @@ ## 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 @@ -44,3 +43,21 @@ ``` [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))
diff --git a/bench/run.cpp b/bench/run.cpp index ccd5ad4..adc911b 100644 --- a/bench/run.cpp +++ b/bench/run.cpp
@@ -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); @@ -27,6 +27,13 @@ } } +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()) { @@ -34,6 +41,20 @@ } } +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()) { @@ -43,7 +64,10 @@ } // 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()