digitalmars.D.learn - time measurement under linux?
- Trass3r (88/88) Jan 19 2009 I wrote a module to ease time measurement in my projects.
- Daniel Keep (3/7) Jan 19 2009 Check std.perf; it's documented, but sadly doesn't show up in the docs.
- Trass3r (2/5) Jan 19 2009 Cool, is similar to my design. Though GetTickCount64 could be added.
- Bill Baxter (5/11) Jan 19 2009 That's odd. I made some updates to std.perf a while back and my
- Jarrett Billingsley (5/11) Jan 19 2009 Namely, PerformanceCounter is crossplatform. (For some reason,
- Trass3r (3/15) Jan 19 2009 HighPerformanceCounter only exists in phobos1 and seems to be redundant
- Bill Baxter (21/40) Jan 19 2009 Oh yeh. That's sounding familiar. The phobos2 version of the file is
- Steven Schveighoffer (4/7) Jan 19 2009 Tango uses gettimeofday, which has microsecond resolution.
- Jason House (2/100) Jan 19 2009
- Jarrett Billingsley (3/8) Jan 19 2009 std.perf has been around for ages <_< it's sad that it isn't documented...
- Bill Baxter (8/18) Jan 19 2009 That's a lot of what I did, actually. A big reason it wasn't showing
I wrote a module to ease time measurement in my projects. Does anyone know how to get elapsed milli- or nanoseconds under linux? Want to make it portable :) module time; version(Windows) import std.c.windows.windows; long frequency; /// frequency of the high performance counter long startTime; /// current measurement start time long curTime; /// current measurement end time const bool hpcAvailable;/// high performance counter supported? /** * initialize the high performance counter */ static this() { version(Win32) { QueryPerformanceFrequency (&frequency); hpcAvailable = false; if (frequency) { hpcAvailable = true; // high performance counter not supported pragma(msg, "high performance counter available"); } } } /** * start measurement */ void start() { version(Windows) { if (hpcAvailable) QueryPerformanceCounter(&startTime); else { version(Win32) startTime = GetTickCount(); version(Win64) startTime = GetTickCount64(); } } } /** * get elapsed milliseconds */ double msecs() { version(Windows) { if (hpcAvailable) { QueryPerformanceCounter(&curTime); return ((curTime-startTime) * 1000) / cast(double) frequency; } else { version(Win32) curTime = GetTickCount(); version(Win64) curTime = GetTickCount64(); return (curTime-startTime); } } } /** * get elapsed nanoseconds */ double nsecs() { version(Windows) { if (hpcAvailable) { QueryPerformanceCounter(&curTime); return ((curTime-startTime) * 1000000) / cast(double) frequency; } else { version(Win32) curTime = GetTickCount(); version(Win64) curTime = GetTickCount64(); return (curTime-startTime) * 1000; } } }
Jan 19 2009
Trass3r wrote:I wrote a module to ease time measurement in my projects. Does anyone know how to get elapsed milli- or nanoseconds under linux? Want to make it portable :) [snip]Check std.perf; it's documented, but sadly doesn't show up in the docs. -- Daniel
Jan 19 2009
Daniel Keep schrieb:Check std.perf; it's documented, but sadly doesn't show up in the docs. -- DanielCool, is similar to my design. Though GetTickCount64 could be added.
Jan 19 2009
On Tue, Jan 20, 2009 at 2:19 AM, Trass3r <mrmocool gmx.de> wrote:Daniel Keep schrieb:That's odd. I made some updates to std.perf a while back and my understanding was that as a result of those Walter was going to put it on the list of documented modules. I guess he just forgot. --bbCheck std.perf; it's documented, but sadly doesn't show up in the docs. -- DanielCool, is similar to my design. Though GetTickCount64 could be added.
Jan 19 2009
On Mon, Jan 19, 2009 at 10:41 AM, Daniel Keep <daniel.keep.lists gmail.com> wrote:Trass3r wrote:Namely, PerformanceCounter is crossplatform. (For some reason, HighPerformanceCounter only works on Windows, even though it uses the same mechanism as PerformanceCounter..)I wrote a module to ease time measurement in my projects. Does anyone know how to get elapsed milli- or nanoseconds under linux? Want to make it portable :) [snip]Check std.perf; it's documented, but sadly doesn't show up in the docs.
Jan 19 2009
Jarrett Billingsley schrieb:On Mon, Jan 19, 2009 at 10:41 AM, Daniel Keep <daniel.keep.lists gmail.com> wrote:HighPerformanceCounter only exists in phobos1 and seems to be redundant anyway (as you said, uses same mechanism).Trass3r wrote:Namely, PerformanceCounter is crossplatform. (For some reason, HighPerformanceCounter only works on Windows, even though it uses the same mechanism as PerformanceCounter..)I wrote a module to ease time measurement in my projects. Does anyone know how to get elapsed milli- or nanoseconds under linux? Want to make it portable :) [snip]Check std.perf; it's documented, but sadly doesn't show up in the docs.
Jan 19 2009
On Tue, Jan 20, 2009 at 6:04 AM, Trass3r <mrmocool gmx.de> wrote:Jarrett Billingsley schrieb:Oh yeh. That's sounding familiar. The phobos2 version of the file is the one with my changes, and the one Walter was supposed to make appear in the docs. Here's what I wrote to walter about the changes I made: """ I didn't end up changing the API. But I did eliminate some classes which I think were dead weight: the ScopePerformanceCounter that just calls start() for you, and the Windows-only HighPerformanceCounter. On versions of Windows that have QueryPerformanceCounter, HighPerformanceCounter and PerformanceCounter do exactly the same thing. On platforms that don't have it, PerformanceCounter uses a backup plan, while HighPerformanceCounter just fails. So there's pretty much no reason to use HighPerformanceCounter, unless you just like code that fails on particular versions of Windows. I was thinking about adding an RDTSC-based timer, but after reading about it a bit, it sounds like its use is discouraged these days, since it is not so reliable on multicore machines. """ ---bbOn Mon, Jan 19, 2009 at 10:41 AM, Daniel Keep <daniel.keep.lists gmail.com> wrote:HighPerformanceCounter only exists in phobos1 and seems to be redundant anyway (as you said, uses same mechanism).Trass3r wrote:Namely, PerformanceCounter is crossplatform. (For some reason, HighPerformanceCounter only works on Windows, even though it uses the same mechanism as PerformanceCounter..)I wrote a module to ease time measurement in my projects. Does anyone know how to get elapsed milli- or nanoseconds under linux? Want to make it portable :) [snip]Check std.perf; it's documented, but sadly doesn't show up in the docs.
Jan 19 2009
"Trass3r" wroteI wrote a module to ease time measurement in my projects. Does anyone know how to get elapsed milli- or nanoseconds under linux? Want to make it portable :)Tango uses gettimeofday, which has microsecond resolution. See tango.time.StopWatch for functionality similar to your code. -Steve
Jan 19 2009
Trass3r wrote:I wrote a module to ease time measurement in my projects. Does anyone know how to get elapsed milli- or nanoseconds under linux? Want to make it portable :)The difficulty of doing platform independent timing is one of the many reasons that drove me to Tango...module time; version(Windows) import std.c.windows.windows; long frequency; /// frequency of the high performance counter long startTime; /// current measurement start time long curTime; /// current measurement end time const bool hpcAvailable;/// high performance counter supported? /** * initialize the high performance counter */ static this() { version(Win32) { QueryPerformanceFrequency (&frequency); hpcAvailable = false; if (frequency) { hpcAvailable = true; // high performance counter not supported pragma(msg, "high performance counter available"); } } } /** * start measurement */ void start() { version(Windows) { if (hpcAvailable) QueryPerformanceCounter(&startTime); else { version(Win32) startTime = GetTickCount(); version(Win64) startTime = GetTickCount64(); } } } /** * get elapsed milliseconds */ double msecs() { version(Windows) { if (hpcAvailable) { QueryPerformanceCounter(&curTime); return ((curTime-startTime) * 1000) / cast(double) frequency; } else { version(Win32) curTime = GetTickCount(); version(Win64) curTime = GetTickCount64(); return (curTime-startTime); } } } /** * get elapsed nanoseconds */ double nsecs() { version(Windows) { if (hpcAvailable) { QueryPerformanceCounter(&curTime); return ((curTime-startTime) * 1000000) / cast(double) frequency; } else { version(Win32) curTime = GetTickCount(); version(Win64) curTime = GetTickCount64(); return (curTime-startTime) * 1000; } } }
Jan 19 2009
On Mon, Jan 19, 2009 at 1:46 PM, Jason House <jason.james.house gmail.com> wrote:Trass3r wrote:std.perf has been around for ages <_< it's sad that it isn't documented.I wrote a module to ease time measurement in my projects. Does anyone know how to get elapsed milli- or nanoseconds under linux? Want to make it portable :)The difficulty of doing platform independent timing is one of the many reasons that drove me to Tango...
Jan 19 2009
On Tue, Jan 20, 2009 at 4:47 AM, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:On Mon, Jan 19, 2009 at 1:46 PM, Jason House <jason.james.house gmail.com> wrote:That's a lot of what I did, actually. A big reason it wasn't showing up in the docs was because it didn't have ddoc comments. So I wrote those, and also did something about portability I think. I don't recall what I did exactly, but there were some code changes too in addition to the ddoc changes. --bbTrass3r wrote:std.perf has been around for ages <_< it's sad that it isn't documented.I wrote a module to ease time measurement in my projects. Does anyone know how to get elapsed milli- or nanoseconds under linux? Want to make it portable :)The difficulty of doing platform independent timing is one of the many reasons that drove me to Tango...
Jan 19 2009