Skip to content

Commit

Permalink
Merge pull request #8 from mourner/rand-benchmarks
Browse files Browse the repository at this point in the history
Add 100k/1m uniform random benchmarks
  • Loading branch information
delfrrr authored Sep 18, 2018
2 parents e8cc6a3 + fb9407a commit f61a3ae
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions bench/run.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
#include "../examples/utils.hpp"
#include <benchmark/benchmark.h>
#include <delaunator.hpp>
#include <random>
#include <string>
#include <vector>

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

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

return coords;
}

namespace {
void BM_45K_geojson_nodes(benchmark::State& state) {
Expand All @@ -12,8 +26,24 @@ void BM_45K_geojson_nodes(benchmark::State& state) {
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_1M_uniform(benchmark::State& state) {
std::vector<double> coords = generate_uniform(1000000);
while (state.KeepRunning()) {
delaunator::Delaunator delaunator(coords);
}
}
} // namespace

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

BENCHMARK_MAIN()

0 comments on commit f61a3ae

Please sign in to comment.