[music-dsp] Re: music-dsp-digest V1 #1224
Alexander R Angas
wgd at internode.on.net
Wed Oct 24 20:31:45 EDT 2001
Thanks! That could be really handy.
> Date: Wed, 24 Oct 2001 10:20:02 -0700
> From: "Jon Watte" <hplus at mindcontrol.org>
> Subject: RE: [music-dsp] Timing in Windoze
>
> > Another, higher resolution timing option if we are
> > talking Win2000 is QueryPerformanceCounter(). Check
> > the following snippet:
> >
> > LARGE_INTEGER tim, freq;
> > double seconds;
> >
> > QueryPerformanceCounter(&tim);
> > QeryPerformanceFrequency(&freq);
> > seconds = (double)tim / (double) freq;
>
>
> QueryPerformanceCounter() is available on most Windows these days (for
sure
> on 98 and up) as long as you have a PCI chipset.
>
> The problem with QPC is that it appears to use some chipset timer which
> takes something like a PCI latency timer window to read, so the minimum
> execution time is a full microsecond; on my machine it takes two
> microseconds to run (I believe it's an actual system call, too).
>
> If you want very low-latency, very accurate measurements of time, use the
> "rdtsc" assembly instruction. It's available from the Pentium on up (an
also
> on AMD chips). It increments one by each CPU clock tick, so for a 1 GHz
> machine, it measures nanoseconds. If you're using NASM, here's some
source:
>
> ; extern __int64 __cdecl read_rdtsc( );
> GLOBAL _read_rdtsc
>
> _read_rdtsc:
> rdtsc
> ret
>
>
>
> Here's some MSVC source:
>
> static __int64 __cdecl __declspec(naked) read_rdtsc( )
> {
> rdtsc
> ret
> }
>
>
> The instruction returns a quadword with the upper 32 bits in EDX, the
lower
> 32 in EAX, which happens to match the calling convention for 64-bit
> integers. Convenient, huh?
>
> The PowerPC has a similar instruction. QuickTime exposes a massaged
version
> of it using the Microseconds() routine.
>
>
> Cheers,
>
> / h+
dupswapdrop -- the music-dsp mailing list and website: subscription info,
FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp/
More information about the music-dsp
mailing list