Thread overview
What's preferred call for getting "d_time"?
Aug 29, 2004
Lynn Allan
Aug 29, 2004
Dave
Sep 23, 2004
Lynn Allan
August 29, 2004
<alert comment="newbie">

I'm hoping to learn enough D to use for a freeware app that involves low-level bit-twiddling. I'd like to sprinkle in calls to obtain "d_time" in order to figure out how much elapsed time is used by different approaches.

As I looked over std.date, it seemed like the best choice was getUTCtime. Is that correct? That routine just calls lower level o/s code, so would it be better to use the o/s call directly? Or is that asking for portability problems? Is there a simpler alternative to getUTCtime? A constructor followed by getting an attribute?

Realistically, getUTCtime is probably fine and my question is pretty much a "poster child" for "premature optimization is the root of most software evil -- Knuth". I ask partly to understand D and phobos better.

d_time startTime = std.date.getUTCtime();
// Code to be timed goes here ...
d_time curTime = getUTCtime();
d_time elapsed = curTime - startTime;

</alert>



August 29, 2004
"Lynn Allan" <l.allan@att.net> wrote in message news:cgrhfn$112t$1@digitaldaemon.com...
> <alert comment="newbie">
>
> I'm hoping to learn enough D to use for a freeware app that involves low-level bit-twiddling. I'd like to sprinkle in calls to obtain "d_time"
in
> order to figure out how much elapsed time is used by different approaches.
>
> As I looked over std.date, it seemed like the best choice was getUTCtime.
Is
> that correct? That routine just calls lower level o/s code, so would it be better to use the o/s call directly? Or is that asking for portability problems? Is there a simpler alternative to getUTCtime? A constructor followed by getting an attribute?
>
> Realistically, getUTCtime is probably fine and my question is pretty much
a
> "poster child" for "premature optimization is the root of most software evil -- Knuth". I ask partly to understand D and phobos better.
>
> d_time startTime = std.date.getUTCtime();
> // Code to be timed goes here ...
> d_time curTime = getUTCtime();
> d_time elapsed = curTime - startTime;
>
> </alert>
>

So far that has worked fine on both Win32 and Linux for me. To get the time in seconds, divide the difference by TicksPerSecond.

If you don't need precision greater than ~1ms, then it should work Ok for you.


September 23, 2004
I did some further looking, and came across: std.perf.HighPerformanceCounter

#import std.stdio;
#import std.c.time;
#import std.perf;

#void main ()
#{
#  HighPerformanceCounter hpc = new HighPerformanceCounter();
#  hpc.start();

#  // Code to be timed goes here ... just msleep for 1.2 seconds
#  std.c.time.msleep(1200);

#  hpc.stop();
#  writefln("hpc ms: ", hpc.microseconds(),
#              "  Seconds: ", hpc.microseconds() / 1000000.0);
#}


"Lynn Allan" <l.allan@att.net> wrote in message news:cgrhfn$112t$1@digitaldaemon.com...
> <alert comment="newbie">
>
> I'm hoping to learn enough D to use for a freeware app that involves low-level bit-twiddling. I'd like to sprinkle in calls to obtain "d_time"
in
> order to figure out how much elapsed time is used by different approaches.
>
> As I looked over std.date, it seemed like the best choice was getUTCtime.
Is
> that correct? That routine just calls lower level o/s code, so would it be better to use the o/s call directly? Or is that asking for portability problems? Is there a simpler alternative to getUTCtime? A constructor followed by getting an attribute?
>
> Realistically, getUTCtime is probably fine and my question is pretty much
a
> "poster child" for "premature optimization is the root of most software evil -- Knuth". I ask partly to understand D and phobos better.
>
> d_time startTime = std.date.getUTCtime();
> // Code to be timed goes here ...
> d_time curTime = getUTCtime();
> d_time elapsed = curTime - startTime;
>
> </alert>
>
>
>