HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerdtsc-1.3.0.1Haskell98

System.CPUTime.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.

As an example, you may use the following program to measure the overhead of calling this function:

module Main where
import System.CPUTime.Rdtsc

main = do
  t1 <- rdtsc
  t2 <- rdtsc
  putStrLn ("Cost of rdtsc (ffi call):    " ++ show (t2 - t1))
  • 1 value
  • Packagerdtsc-1.3.0.1
  • Exports1
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceRdtsc.hs
valuerdtsc :: IO Word64
#

Return the number of clock cycles since the machine this function is called on has been powered up. Note that the value returned may be inaccurate if the program is run on some hardware virtualization layer.

Especially on multi-core processors and when using hibernating operating systems, the values returned may be bogus.

For more information about the rdtsc instruction, see http://en.wikipedia.org/wiki/RDTSC