The rdtsc package

[Tags: bsd3, library]

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.

Also 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 88 cycles.

[Skip to ReadMe]


Versions1.1.1, 1.1.3,,,,
Dependenciesbase (==4.*) [details]
AuthorMartin Grabmueller <>
CategoryForeign binding
Home page
Bug tracker
Source repositoryhead: git clone
UploadedTue May 26 15:17:33 UTC 2015 by MartinGrabmueller
Downloads1123 total (36 in last 30 days)
0 []
StatusDocs available [build log]
Last success reported on 2015-05-27 [all 1 reports]




Maintainers' corner

For package maintainers and hackage trustees

Readme for rdtsc-

rdtsc - Binding for the rdtsc machine instruction

This small Cabal package provides a Haskell binding to the "rdtsc" machine instruction on modern IA-32 processors. This instruction can be used to read the number of cycles since processor startup and gives very accurate timing information.

Note: this package contains the file cycle.h by Matteo Frigo, which provides access to cycle counters on several architectures. The license for this file is included in the file LICENSE in this package.



cabal install rdtsc

for building and installing system-wide, or

tar xzvf rdtsc-X.Y.Z.W.tar.gz
cd rdtsc-X.Y.Z.W
cabal sandbox init
cabal install

for building and installing in a sandbox.

Just import module "System.CPUTime.Rdtsc" into your Haskell file and use

ghc --make FILENAME

to compile your program.

The "tests" directory contains a small test program for the module and demonstrates its usage. There is also a C version for this test program, to test the overheads of Haskell's FFI.

Happy Haskell hacking, Martin