[Haskell-cafe] Announce: Package rdtsc for reading IA-32 time stamp counters

Martin Grabmueller magr at cs.tu-berlin.de
Tue Jan 2 09:00:03 EST 2007

Hallo all,

version 1.0 of package rdtsc has just been released.

This small package contains one module called 'Rdtsc.Rdtsc'.

This module provides the function 'rdtsc' for accessing
the 'rdtsc' machine register on modern IA-32 processors.  This is
a 64-bit counter which counts the number of processor cycles since
the machine has been powered up.  Using this instruction, you can
make very precise time measurements which are independent of the
actual CPU frequency.  But note that you can get strange results
sometimes on a superscalar processor.

A small program using this library looks like this:

  module Main where
  import Rdtsc.Rdtsc
  main = do
    t1 <- rdtsc
    t2 <- rdtsc
    putStrLn ("Cost of rdtsc (ffi call): " ++ show (t2 - t1))

Note that the Haskell foreign function interface imposes some
additional overheads.  On my machine, it takes about 950 cycles to
call this function twice and to compute the difference, whereas in
C the overhead is only about 84 cycles.

The documentation for the package is available here:


Download the source using darcs:

  darcs get http://uebb.cs.tu-berlin.de/~magr/darcs/rdtsc/

I would really like to get feedback on this little package, which
already has been quite useful for me.

Have fun and Happy Haskell Hacking in th New Year,

More information about the Haskell-Cafe mailing list