On Wednesday, 22 July 2015 at 09:23:36 UTC, Clayton wrote:
How does one represent Duration in only Micro-seconds, or milliseconds. Trying to measure the execution time of an algorithm and I get "4 ms, 619 μs, and 8 hnsecs" , I want to sum all these and get total hnsecs or μs .

I would also appreciate advise on whether this is the best way to measure the execution time of an algorithm.



import std.datetime;
import std.stdio;

void algorithm( ){
        writeln("Hello!");
}
void main(){

        auto stattime = Clock.currTime();
        algorithm( );
        endttime = Clock.currTime();

        auto duration = endttime - stattime;

        writeln("Hello Duration ==> ", duration);

}

The normal way of doing this would be using std.datetime.StopWatch:

    StopWatch sw;
    sw.start();
    algorithm();
    long exec_ms = sw.peek().msecs;

Reply via email to