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 File Reference

Wall-clock + cycle-accurate benchmarking for performance profiling. More...

#include <chrono>
#include <functional>
#include <iostream>
#include <string>

Go to the source code of this file.

Functions

void benchmark (const std::string &name, int trials, std::function< int()> func)
 Benchmark wrapper that logs wall time and CPU cycles.
 

Detailed Description

Wall-clock + cycle-accurate benchmarking for performance profiling.

Wraps a simulation function and logs:

  • Wall time in nanoseconds + seconds
  • CPU cycles (via rdtsc or cntvct_el0)
  • π estimate from number of hits

Features

  • Cross-platform CPU cycle counting (x86 + ARM)
  • High-resolution std::chrono timer
  • Printable results for logging or scripting

Example

benchmark("SIMD", 10000000, [&]() {
return monteCarloPI_SEQUENTIAl(10000000);
});
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
int monteCarloPI_SEQUENTIAl(int numberOfTrials)
Estimates π using sequential dart throwing.

Definition in file benchmark.hpp.

Function Documentation

◆ benchmark()

void benchmark ( const std::string & name,
int trials,
std::function< int()> func )

Benchmark wrapper that logs wall time and CPU cycles.

Times the execution of a function using both std::chrono. Outputs hit count and estimate of π. duration in seconds and nanoseconds

Parameters
nameName of the benchmark (e.g., "SIMD")
trialsTotal number of Monte Carlo trials
funcFunction that returns number of hits

Definition at line 44 of file benchmark.hpp.

44 {
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}