benchmark

Benchmarks code for speed assessment and comparison.

Duration[fun.length]
benchmark
(
fun...
)
(
uint n
)

Parameters

fun

aliases of callable objects (e.g. function names). Each callable object should take no arguments.

n uint

The number of times each function is to be executed.

Return Value

Type: Duration[fun.length]

The amount of time (as a core.time.Duration) that it took to call each function n times. The first value is the length of time that it took to call fun[0] n times. The second value is the length of time it took to call fun[1] n times. Etc.

Examples

import std.conv : to;

int a;
void f0() {}
void f1() { auto b = a; }
void f2() { auto b = to!string(a); }
auto r = benchmark!(f0, f1, f2)(10_000);
Duration f0Result = r[0]; // time f0 took to run 10,000 times
Duration f1Result = r[1]; // time f1 took to run 10,000 times
Duration f2Result = r[2]; // time f2 took to run 10,000 times

Meta