Benchmarking in D
Robert Jacques
sandford at jhu.edu
Sun Apr 11 06:42:14 PDT 2010
On Sun, 11 Apr 2010 05:27:58 -0300, Chris Mueller <ruunhb at googlemail.com>
wrote:
> Hi everyone,
>
> I would like to benchmark some of my D routines for performance testing
> and like to compare it with some alternative implementations in e.g.
> time and memory consumption.
>
> I'm not really experienced in this field and want to ask if someone can
> share his knowledge.
>
> Are there some tools providing by the operating system to look at the
> performance of a process? Are there any libraries in D that can help?
>
>
> Chris
Here's a little benchmark routine I use:
import std.perf;
import core.thread;
import std.stdio;
import std.algorithm;
void bench(R)(string label, R delegate() dg, uint times = 1 ) {
scope pc = new PerformanceCounter;
real time = uint.max;
foreach(i;0..times) {
pc.start;
dg();
pc.stop;
time = min(time,pc.microseconds/1000.0);
Thread.yield;
}
writeln(label,time,"ms");
}
More information about the Digitalmars-d
mailing list