27 void GenerateTemplateResults(
const std::vector<ankerl::nanobench::Result>& benchmarkResults,
const fs::path& file,
const char* tpl)
29 if (benchmarkResults.empty() || file.empty()) {
33 std::ofstream fout{file};
36 std::cout <<
"Created " << file << std::endl;
38 std::cout <<
"Could not write to file " << file << std::endl;
46 static std::map<std::string, BenchFunction> benchmarks_map;
47 return benchmarks_map;
52 benchmarks().insert(std::make_pair(
name, func));
57 std::regex reFilter(
args.regex_filter);
58 std::smatch baseMatch;
60 if (
args.sanity_check) {
61 std::cout <<
"Running with --sanity-check option, benchmark results will be useless." << std::endl;
64 std::vector<ankerl::nanobench::Result> benchmarkResults;
65 for (
const auto& p : benchmarks()) {
66 if (!std::regex_match(p.first, baseMatch, reFilter)) {
70 if (
args.is_list_only) {
71 std::cout << p.first << std::endl;
76 if (
args.sanity_check) {
80 if (
args.min_time > 0ms) {
82 std::chrono::nanoseconds min_time_ns =
args.min_time;
86 if (
args.asymptote.empty()) {
89 for (
auto n :
args.asymptote) {
96 if (!bench.results().empty()) {
97 benchmarkResults.push_back(bench.results().back());
101 GenerateTemplateResults(benchmarkResults,
args.output_csv,
"# Benchmark, evals, iterations, total, min, max, median\n" 102 "{{#result}}{{name}}, {{epochs}}, {{average(iterations)}}, {{sumProduct(iterations, elapsed)}}, {{minimum(elapsed)}}, {{maximum(elapsed)}}, {{median(elapsed)}}\n" char const * json() noexcept
Template to generate JSON data.
BenchRunner(std::string name, BenchFunction func)
Bench & epochIterations(uint64_t numIters) noexcept
Sets exactly the number of iterations for each epoch.
const std::function< void(const std::string &)> G_TEST_LOG_FUN
This is connected to the logger.
void render(char const *mustacheTemplate, Bench const &bench, std::ostream &out)
Renders output from a mustache-like template and benchmark results.
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
Bench & complexityN(T b) noexcept
std::function< void(Bench &)> BenchFunction
std::map< std::string, BenchFunction > BenchmarkMap
ANKERL_NANOBENCH(NODISCARD) std Bench & minEpochTime(std::chrono::nanoseconds t) noexcept
Minimum time each epoch should take.
static void RunAll(const Args &args)
Bench & epochs(size_t numEpochs) noexcept
Controls number of epochs, the number of measurements to perform.
static BenchmarkMap & benchmarks()
Main entry point to nanobench's benchmarking facility.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
const std::function< std::vector< const char * >)> G_TEST_COMMAND_LINE_ARGUMENTS
Retrieve the command line arguments.