ddn.util.monaco.benchmark

Performance benchmarking and profiling utilities.

This module provides tools for measuring execution time, memory usage, and comparing performance across different implementations. It is designed to help optimize the Monaco library for maximum performance.

Types 6

Represents a single benchmark measurement.

Fields
string nameName of the benchmark
Duration meanTimeMean execution time
Duration stdevTimeStandard deviation of execution times
Duration minTimeMinimum execution time
Duration maxTimeMaximum execution time
uint iterationsNumber of iterations
Duration totalTimeTotal time for all iterations
double opsPerSecondOperations per second
ulong memoryUsedMemory allocated (if available)

Statistics from multiple benchmark runs.

Fields
BenchmarkResult[] resultsIndividual benchmark results
SysTime timestampTimestamp when benchmarks were run
Duration totalDurationTotal duration of all benchmarks
string systemInfoSystem information when benchmarks were run

Configuration for benchmark execution.

Fields
uint warmupIterationsNumber of warm-up iterations (default: 3)
uint measurementIterationsNumber of measurement iterations (default: 10)
Duration minIterationTimeMinimum duration for each iteration (default: 1ms)
Duration maxIterationTimeMaximum duration for each iteration (default: 10s)
bool collectMemoryWhether to collect memory statistics
bool verboseWhether to print progress information
classBenchmarkException : Exception

Exception thrown when benchmark operations fail.

Constructors
this(string msg, string file = __FILE__, size_t line = __LINE__)

High-precision benchmark runner.

This class provides utilities for measuring the performance of functions with statistical analysis and warm-up phases.

Example:

auto bench = new BenchmarkRunner();
auto result = bench.benchmark!("cpuStats", &cpuStats);
writeln(result);

Fields
private BenchmarkConfig config
private StopWatch stopwatch
Methods
BenchmarkResult benchmark(string name, void delegate() @safe func) @safeBenchmarks a function with automatic warm-up and measurement.
Tuple!(T, "value", BenchmarkResult, "stats") benchmarkWithResult(T)(string name, T delegate() @safe func) @safeBenchmarks a function that returns a value.
BenchmarkStats runSuite(Tuple!(string, void delegate() @safe)[] benchmarks) @safeRuns multiple benchmarks and returns combined statistics.
BenchmarkConfig configuration() @safe pure nothrowGets the current configuration.
void setConfiguration(BenchmarkConfig cfg) @safe pure nothrowSets the configuration.
private BenchmarkResult calculateStatistics(string name, Duration[] times, Duration total) @trusted
private string getSystemInfo() @safe
Constructors
this()Creates a new benchmark runner with default configuration.
this(BenchmarkConfig cfg)Creates a new benchmark runner with custom configuration.

Memory profiler for tracking allocations.

This class provides utilities for measuring memory usage during benchmark runs.

Fields
private size_t allocated
private size_t freed
private size_t peak
Methods
void start() @safe pure nothrowStarts a memory profiling session.
void allocate(size_t size) @safe pure nothrowRecords an allocation.
void deallocate(size_t size) @safe pure nothrowRecords a deallocation.
size_t totalAllocated() @safe pure nothrowGets the total number of bytes allocated.
size_t currentUsage() @safe pure nothrowGets the current memory usage.
size_t peakUsage() @safe pure nothrowGets the peak memory usage.
void reset() @safe pure nothrowResets the profiler state.

Functions 5

fnstring formatBenchmarkResult(BenchmarkResult result) @safeFormats a benchmark result for display.
fnstring compareBenchmarks(BenchmarkResult baseline, BenchmarkResult current) @safeCompares two benchmark results.
fnBenchmarkStats runMonacoBenchmarks() @safeRuns the Monaco benchmark suite.
private fnT abs(T)(T value) @safe pure nothrow
private fndouble sqrt(double x) @safe pure nothrow