Simple, fast, accurate microbenchmarking functionality for C++11/14/17/20
int benchsIterations[] = {2, 8, 16, 32, 64, 256, 1024, 1024 * 1024};
for (int nbValues : benchsIterations)
{
cfg.title("Summation " + std::to_string(nbValues)).relative(true).minEpochIterations(50).minEpochTime(10ms);
nanobench::Rng rng;
std::vector<Scalar> values(nbValues);
std::generate(values.begin(), values.end(), [&] { return Scalar(rng.uniform01()); });
cfg.run("Naive raw sum", [&] {
const Scalar* beg = values.data();
Scalar acc = naive_sum(beg, beg + nbValues);
nanobench::doNotOptimizeAway(acc);
});
// More benchs
// I need to call render here, because if put out of the loop it will only render for the last loop
}
case Node::Type::tag:
- if (n == "unit") {
- out << bench.unit();
- } else if (n == "title") {
- out << bench.title();
- } else if (n == "batch") {
- out << bench.batch();
- } else {
- throw std::runtime_error("unknown tag '" + std::string(n.begin, n.end) + "'");
- }
+ throw std::runtime_error("unknown tag '" + std::string(n.begin, n.end) + "'");
break;
}
}
generate
now takes only a std::vector<Result>
and not Bench
as param
and adds a 10% noise
while it's a 20% noise :)
./external/nanobench/include\nanobench.h:444:19: error: couldn't allocate input reg for constraint 'r'
asm volatile("" : : "r"(val) : "memory");
^
asm volatile("" : : "r,m"(val) : "memory");
works though