www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - best D equivalent to C'stimeval

reply "ed" <sillymongrel gmail.com> writes:
Hi,

Just wondering what the best replacement for C timeval is in D. 
I'm looking at std.datetime.SysTime, but std.datetime is huge so 
I'm not sure.

Thanks,
ed
Mar 30 2014
next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Monday, March 31, 2014 05:09:22 ed wrote:
 Hi,
 
 Just wondering what the best replacement for C timeval is in D.
 I'm looking at std.datetime.SysTime, but std.datetime is huge so
 I'm not sure.
If you want an overview of std.datetime, read http://dlang.org/intro-to-datetime.html But yes, SysTime would be what you'd want to use instead of a timeval. SysTime is intended for representing the time of the system, whereas DateTime, Date, or TimeOfDay relate to specifically to calendar time (they have no time zones and therefore cannot be tied to a unique point in time - e.g. a DateTime for 2014-03-30T12:00:00 could be one of over 24 different points in time, as it has no time zone to tie it down). SysTime holds its time internally in UTC and uses a TimeZone object to convert to to other time zones when required (e.g. when printing it out); it defaults to LocalTime, which represents the local time of your system. SysTime also has a function called toTimeVal for converting to a timeval if you need to pass it to C code. - Jonathan M Davis
Mar 30 2014
parent "ed" <sillymongrel gmail.com> writes:
On Monday, 31 March 2014 at 06:25:40 UTC, Jonathan M Davis wrote:
 On Monday, March 31, 2014 05:09:22 ed wrote:
 Hi,
 
 Just wondering what the best replacement for C timeval is in D.
 I'm looking at std.datetime.SysTime, but std.datetime is huge 
 so
 I'm not sure.
If you want an overview of std.datetime, read http://dlang.org/intro-to-datetime.html But yes, SysTime would be what you'd want to use instead of a timeval. SysTime is intended for representing the time of the system, whereas DateTime, Date, or TimeOfDay relate to specifically to calendar time (they have no time zones and therefore cannot be tied to a unique point in time - e.g. a DateTime for 2014-03-30T12:00:00 could be one of over 24 different points in time, as it has no time zone to tie it down). SysTime holds its time internally in UTC and uses a TimeZone object to convert to to other time zones when required (e.g. when printing it out); it defaults to LocalTime, which represents the local time of your system. SysTime also has a function called toTimeVal for converting to a timeval if you need to pass it to C code. - Jonathan M Davis
Great info, thank you. Cheers, ed
Mar 30 2014
prev sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Mon, 31 Mar 2014 05:09:22 +0000
schrieb "ed" <sillymongrel gmail.com>:

 Hi,
 
 Just wondering what the best replacement for C timeval is in D. 
 I'm looking at std.datetime.SysTime, but std.datetime is huge so 
 I'm not sure.
 
 Thanks,
 ed
If you just need to time something, TickDuration from core.time is an efficient cross-platform timer. auto t1 = TickDuration.currentSystemTick; ... auto t2 = TickDuration.currentSystemTick; writefln("Took %s ms", (t2-t1).msecs); -- Marco
Mar 31 2014