View source code Display the source code in std/datetime.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.datetime.benchmark

Benchmarks code for speed assessment and comparison.

Prototype

TickDuration[fun.length] benchmark(fun...)(
  uint n
);

Parameters

NameDescription
fun aliases of callable objects (e.g. function names). Each should take no arguments.
n The number of times each function is to be executed.

Returns

The amount of time (as a core.time.TickDuration) 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.

Note that casting the TickDurations to core.time.Durations will make the results easier to deal with (and it may change in the future that benchmark will return an array of Durations rather than TickDurations).

See Also

measureTime

Example

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);
auto f0Result = to!Duration(r[0]); // time f0 took to run 10,000 times
auto f1Result = to!Duration(r[1]); // time f1 took to run 10,000 times
auto f2Result = to!Duration(r[2]); // time f2 took to run 10,000 times

Authors

Jonathan M Davis and Kato Shoichi

License

Boost License 1.0.

Comments