scheduleForBenchmarking

The examples shown so far feature simple, ad-hoc benchmarks, but std.benchmark allows for superior automation and systematic use aimed at large projects.

The code mixin(scheduleForBenchmarking) planted at module level schedules the entire module for benchmarking. The actual benchmarking can be done globally by calling printBenchmarks (with no arguments) or runBenchmarks. Either call is usually made from main.

In a multi-module application, several modules may define benchmarks, and printBenchmarks distinguishes each visually.

@property
string
scheduleForBenchmarking
()

Examples

module nxt.acme;
import std.file, std.array;

void benchmark_fileWrite()
{
	std.file.write("/tmp/deleteme", "hello, world!");
}

void benchmark_relative_fileRead()
{
	std.file.read("/tmp/deleteme");
}

mixin(scheduleForBenchmarking);

Typically the mixin is guarded by a version so benchmarks are only run if desired.

version (benchmark_enabled) mixin(scheduleForBenchmarking);

Meta