File: Overhead.hs

package info (click to toggle)
haskell-criterion 1.6.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 352 kB
  • sloc: haskell: 1,839; javascript: 811; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,032 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-- This benchmark measures the timing overhead added by the various
-- functions we use to measure performance.

{-# LANGUAGE CPP #-}

module Main (main) where

import Criterion.Main
import Criterion.Measurement as M
import GHC.Stats as GHC

main :: IO ()
main = do
  M.initializeTime -- Need to do this before calling M.getTime
  statsEnabled <- getRTSStatsEnabled
  defaultMain $ [
      bench "measure" $           whnfIO (M.measure (whnfIO $ return ()) 1)
    , bench "getTime" $           whnfIO M.getTime
    , bench "getCPUTime" $        whnfIO M.getCPUTime
    , bench "getCycles" $         whnfIO M.getCycles
    , bench "M.getGCStatistics" $ whnfIO M.getGCStatistics
    ] ++ if statsEnabled
         then [bench
#if MIN_VERSION_base(4,10,0)
                     "GHC.getRTSStats" $ whnfIO GHC.getRTSStats
#else
                     "GHC.getGCStats" $  whnfIO GHC.getGCStats
#endif
              ]
         else []

#if !MIN_VERSION_base(4,10,0)
getRTSStatsEnabled :: IO Bool
getRTSStatsEnabled = getGCStatsEnabled
#endif