time measurement under linux?

Bill Baxter wbaxter at gmail.com
Mon Jan 19 13:17:39 PST 2009


On Tue, Jan 20, 2009 at 6:04 AM, Trass3r <mrmocool at gmx.de> wrote:
> Jarrett Billingsley schrieb:
>>
>> On Mon, Jan 19, 2009 at 10:41 AM, Daniel Keep
>> <daniel.keep.lists at gmail.com> wrote:
>>>
>>> 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.
>>
>> Namely, PerformanceCounter is crossplatform.  (For some reason,
>> HighPerformanceCounter only works on Windows, even though it uses the
>> same mechanism as PerformanceCounter..)
>
> HighPerformanceCounter only exists in phobos1 and seems to be redundant
> anyway (as you said, uses same mechanism).

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.
"""

---bb


More information about the Digitalmars-d-learn mailing list