Benchmarking Time Unit

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 1 11:39:01 PDT 2016


On Tuesday, November 01, 2016 16:53:51 Nordlöw via Digitalmars-d-learn 
wrote:
> Which way of measuring time in std.datetime should I used if I
> want to benchmark a function by the amount of time spent in the
> current thread, not wall-clock time?

That's what std.datetime.benchmark is for, though unfortunately, it still
uses core.time.TickDuration rather using core.time.MonoTime and
core.time.Duration.

Alternatively, you can always do something like

immutable before = MonoTime.currTime();
// do stuf...
immutable after = MonoTime.currTime();
Duration timeSpent = after - before;

though that just times how long something took rather than running it over
and over again like benchmark does.

I really need to get replacements for the TickDuration-related stuff in
std.datetime into std.experimental so that we can move towards replacing it
and finally getting rid of TickDuration, but I haven't gotten to it yet.

- Jonathan M Davis




More information about the Digitalmars-d-learn mailing list