std.benchmark

Members

Aliases

AutoStart
alias AutoStart = std.datetime.AutoStart
ComparingBenchmarkResult
alias ComparingBenchmarkResult = std.datetime.ComparingBenchmarkResult
StopWatch
alias StopWatch = std.datetime.StopWatch
comparingBenchmark
alias comparingBenchmark = std.datetime.comparingBenchmark
measureTime
alias measureTime = std.datetime.measureTime

Aliases from std.datetime.

Functions

addBenchmarks
void addBenchmarks(void function(ref BenchmarkResult[], string) fun, string moduleName)
Undocumented in source. Be warned that the author may not have intended to support it.
benchmark
void benchmark(BenchmarkResult[] results, string moduleName)

Benchmarks functions and appends the results to the results parameter. This function is used by printBenchmarks, and the funs parameter has the same requirements as for that function.

benchmarkModuleCodegen
string benchmarkModuleCodegen(string[] funs)
Undocumented in source. Be warned that the author may not have intended to support it.
benchmarkResume
void benchmarkResume()

Suspends and resumes the current benchmark, respectively. This is useful if the benchmark needs to set things up before performing the measurement.

benchmarkSuspend
void benchmarkSuspend()

Suspends and resumes the current benchmark, respectively. This is useful if the benchmark needs to set things up before performing the measurement.

printBenchmarks
void printBenchmarks(File target)

Benchmarks one or more functions for speed assessment and comparison, and prints results as formatted text. A baseline timing that accounts for benchmarking overheads is kept along with the results and automatically deducted from all timings. A timing indistinguishable from the baseline looping overhead appears with a run time of zero and indicates a function that does too little work to be timed.

printResults
void printResults(BenchmarkResult[] data, File target)

Prints benchmark results as described with printBenchmarks. This is useful if benchmark postprocessing is desired before printing.

runBenchmarks
void runBenchmarks(BenchmarkResult[] results)

Performs all benchmarks previously scheduled with scheduleForBenchmarking, application-wide. Usually not called directly, but instead as support for printBenchmarks. User code may be interested in using this function directly for e.g. results formatting.

Properties

scheduleForBenchmarking
string scheduleForBenchmarking [@property getter]

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

Structs

BenchmarkResult
struct BenchmarkResult

Result of one function's benchmark.

Meta

Source

See Source File
std/benchmark.d

Synopsis:

module nxt.module_one;
import std.benchmark, std.file;

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

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

mixin(scheduleForBenchmarking);

void main()
{
	printBenchmarks();
}

The code above prints:

===============================================================================
module_one											 relative ns/iter  iter/s
===============================================================================
fileWrite														144.2K	6.9K
fileRead														  27.1K   36.9K
===============================================================================