www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - What's preferred call for getting "d_time"?

reply "Lynn Allan" <l.allan att.net> writes:
<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>
Aug 28 2004
next sibling parent "Dave" <Dave_member pathlink.com> writes:
"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.
Aug 29 2004
prev sibling parent "Lynn Allan" <l_d_allan adelphia.net> writes:
I did some further looking, and came across:
std.perf.HighPerformanceCounter

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

#void main ()













"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>
Sep 23 2004