9#include <test/util/setup_common.h>
19using namespace std::chrono_literals;
23void GenerateTemplateResults(
24 const std::vector<ankerl::nanobench::Result> &benchmarkResults,
25 const fs::path &file,
const char *tpl) {
26 if (benchmarkResults.empty() || file.empty()) {
30 std::ofstream fout{file};
33 std::cout <<
"Created " << file << std::endl;
35 std::cout <<
"Could not write to file " << file << std::endl;
42 static std::map<std::string, BenchFunction> benchmarks_map;
43 return benchmarks_map;
48 benchmarks().insert(std::make_pair(
name, func));
53 std::smatch baseMatch;
55 std::vector<ankerl::nanobench::Result> benchmarkResults;
57 for (
const auto &p : benchmarks()) {
58 if (!std::regex_match(p.first, baseMatch, reFilter)) {
63 std::cout << p.first << std::endl;
71 std::chrono::nanoseconds min_time_ns = args.
min_time;
84 benchmarkResults.push_back(bench.results().back());
87 GenerateTemplateResults(
89 "# Benchmark, evals, iterations, total, min, max, median\n"
90 "{{#result}}{{name}}, {{epochs}}, {{average(iterations)}}, "
91 "{{sumProduct(iterations, elapsed)}}, {{minimum(elapsed)}}, "
92 "{{maximum(elapsed)}}, {{median(elapsed)}}\n"
94 GenerateTemplateResults(benchmarkResults, args.
output_json,
Main entry point to nanobench's benchmarking facility.
Bench & complexityN(T b) noexcept
Bench & epochs(size_t numEpochs) noexcept
Controls number of epochs, the number of measurements to perform.
ANKERL_NANOBENCH(NODISCARD) std Bench & name(char const *benchmarkName)
Name of the benchmark, will be shown in the table row.
std::vector< BigO > complexityBigO() const
ANKERL_NANOBENCH(NODISCARD) std Bench & minEpochTime(std::chrono::nanoseconds t) noexcept
Minimum time each epoch should take.
static BenchmarkMap & benchmarks()
static void RunAll(const Args &args)
std::map< std::string, BenchFunction > BenchmarkMap
BenchRunner(std::string name, BenchFunction func)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
char const * json() noexcept
Template to generate JSON data.
void render(char const *mustacheTemplate, Bench const &bench, std::ostream &out)
Renders output from a mustache-like template and benchmark results.
std::function< void(Bench &)> BenchFunction
std::vector< double > asymptote
std::chrono::milliseconds min_time