digitalmars.D - What's preferred call for getting "d_time"?
-
Lynn Allan
(17/17)
Aug 28 2004
- Dave (9/26) Aug 29 2004 in
- Lynn Allan (20/37) Sep 23 2004 I did some further looking, and came across:
<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
"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"inorder 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.Isthat 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 mucha"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
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"inorder 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.Isthat 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 mucha"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