Files
weaseldb/benchmarks/bench_cpu_work.cpp
Andrew Noyes 0357a41dd8 Implement spend_cpu_cycles in assembly
The compiler was unrolling it previously, so we're doing assembly now for consistency.
2025-09-05 15:16:49 -04:00

35 lines
895 B
C++

#include <iostream>
#include <nanobench.h>
#include <string>
#include "../src/cpu_work.hpp"
int main(int argc, char *argv[]) {
int iterations = DEFAULT_HEALTH_CHECK_ITERATIONS;
if (argc > 1) {
try {
iterations = std::stoi(argv[1]);
if (iterations < 0) {
std::cerr << "Error: iterations must be non-negative" << std::endl;
return 1;
}
} catch (const std::exception &e) {
std::cerr << "Error: invalid number '" << argv[1] << "'" << std::endl;
return 1;
}
}
std::cout << "Benchmarking spend_cpu_cycles with " << iterations
<< " iterations" << std::endl;
ankerl::nanobench::Bench bench;
bench.minEpochIterations(10000);
// Benchmark the same CPU work that health checks use
bench.run("spend_cpu_cycles(" + std::to_string(iterations) + ")",
[&] { spend_cpu_cycles(iterations); });
return 0;
}