Monte Carlo Benchmarking Engine
High-performance SIMD Monte Carlo engine (AVX2/NEON) with custom memory allocators and perf logging.
 
Loading...
Searching...
No Matches
benchmark.hpp
Go to the documentation of this file.
1// ========================================
2// benchmark.hpp - Timing Utility Wrapper
3// ========================================
25
26#pragma once
27
28#include <chrono>
29#include <functional>
30#include <iostream>
31#include <string>
32
44inline void benchmark(const std::string& name, int trials, std::function<int()> func) {
45 auto start = std::chrono::high_resolution_clock::now();
46
47 int hits = func();
48
49 auto end = std::chrono::high_resolution_clock::now();
50
51 double piEstimate = 4.0 * hits / trials;
52 auto elapsed_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
53
54 std::cout << name << ":\n"
55 << " Trials: " << trials << "\n"
56 << " Hits: " << hits << "\n"
57 << " Estimate: " << piEstimate << "\n"
58 << " Time: " << (elapsed_ns / 1e9) << "s (" << elapsed_ns << " ns)\n";
59}
void benchmark(const std::string &name, int trials, std::function< int()> func)
Benchmark wrapper that logs wall time and CPU cycles.
Definition benchmark.hpp:44