55#include < string>
66#include < vector>
77
8+ namespace {
89std::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 {
2121void 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+
3037void 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+
3758void 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
4566BENCHMARK (BM_45K_geojson_nodes)->Unit(benchmark::kMillisecond );
67+ BENCHMARK (BM_2K_uniform)->Unit(benchmark::kMillisecond );
4668BENCHMARK (BM_100K_uniform)->Unit(benchmark::kMillisecond );
69+ BENCHMARK (BM_200K_uniform)->Unit(benchmark::kMillisecond );
70+ BENCHMARK (BM_500K_uniform)->Unit(benchmark::kMillisecond );
4771BENCHMARK (BM_1M_uniform)->Unit(benchmark::kMillisecond );
4872
4973BENCHMARK_MAIN ()
0 commit comments