Logo

Programming-Idioms

  • Groovy
  • D
import std.datetime;
auto elapsed = benchmark!f(1)[0].msecs;

benchmark measures n executions of the function
import std.datetime.stopwatch;
auto timer = StopWatch(AutoStart.yes);
f();
timer.stop();

writeln("Time taken: ", timer.peek.total!"msecs"());

The standard procedural way
import std.datetime;
{
    import std.stdio;
    auto mt = measureTime!((TickDuration a{writeln(a.msecs);});
    f();
}

The level 0 braces are used to create a scope.
(time (f))

New implementation...
< >
programming-idioms.org