Aliases from std.datetime.
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.
Suspends and resumes the current benchmark, respectively. This is useful if the benchmark needs to set things up before performing the measurement.
Suspends and resumes the current benchmark, respectively. This is useful if the benchmark needs to set things up before performing the measurement.
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.
Prints benchmark results as described with printBenchmarks. This is useful if benchmark postprocessing is desired before printing.
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.
The examples shown so far feature simple, ad-hoc benchmarks, but std.benchmark allows for superior automation and systematic use aimed at large projects.
Result of one function's benchmark.
See Source File
std/benchmark.d
Synopsis:
1 module nxt.module_one; 2 import std.benchmark, std.file; 3 4 void benchmark_fileWrite() 5 { 6 std.file.write("/tmp/deleteme", "hello, world!"); 7 } 8 9 void benchmark_fileRead() 10 { 11 std.file.read("/tmp/deleteme"); 12 } 13 14 mixin(scheduleForBenchmarking); 15 16 void main() 17 { 18 printBenchmarks(); 19 }
The code above prints:
=============================================================================== module_one relative ns/iter iter/s =============================================================================== fileWrite 144.2K 6.9K fileRead 27.1K 36.9K ===============================================================================
Copyright 2011-