Skip to content

Commit f61a3ae

Browse files
authored
Merge pull request #8 from mourner/rand-benchmarks
Add 100k/1m uniform random benchmarks
2 parents e8cc6a3 + fb9407a commit f61a3ae

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

bench/run.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
#include "../examples/utils.hpp"
22
#include <benchmark/benchmark.h>
33
#include <delaunator.hpp>
4+
#include <random>
45
#include <string>
6+
#include <vector>
7+
8+
std::vector<double> generate_uniform(size_t n) {
9+
std::vector<double> coords;
10+
std::srand(350);
11+
12+
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);
15+
}
16+
17+
return coords;
18+
}
519

620
namespace {
721
void BM_45K_geojson_nodes(benchmark::State& state) {
@@ -12,8 +26,24 @@ void BM_45K_geojson_nodes(benchmark::State& state) {
1226
delaunator::Delaunator delaunator(coords);
1327
}
1428
}
29+
30+
void BM_100K_uniform(benchmark::State& state) {
31+
std::vector<double> coords = generate_uniform(100000);
32+
while (state.KeepRunning()) {
33+
delaunator::Delaunator delaunator(coords);
34+
}
35+
}
36+
37+
void BM_1M_uniform(benchmark::State& state) {
38+
std::vector<double> coords = generate_uniform(1000000);
39+
while (state.KeepRunning()) {
40+
delaunator::Delaunator delaunator(coords);
41+
}
42+
}
1543
} // namespace
1644

1745
BENCHMARK(BM_45K_geojson_nodes)->Unit(benchmark::kMillisecond);
46+
BENCHMARK(BM_100K_uniform)->Unit(benchmark::kMillisecond);
47+
BENCHMARK(BM_1M_uniform)->Unit(benchmark::kMillisecond);
1848

1949
BENCHMARK_MAIN()

0 commit comments

Comments
 (0)