Skip to content

Commit

Permalink
Replace package 'time' with 'clock' to fix timer precision on Windows…
Browse files Browse the repository at this point in the history
…. Only tested on Windows 7.
  • Loading branch information
conklech committed Apr 9, 2013
1 parent 972d9a4 commit b6f657c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Criterion/Measurement.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Criterion.Measurement
) where

import Control.Monad (when)
import Data.Time.Clock.POSIX (getPOSIXTime)
import qualified System.Clock as Clock (Clock(Monotonic), getTime, sec, nsec)
import Text.Printf (printf)

time :: IO a -> IO (Double, a)
Expand All @@ -40,7 +40,11 @@ time_ act = do
return $! end - start

getTime :: IO Double
getTime = realToFrac `fmap` getPOSIXTime
getTime = tSpecToDouble `fmap` Clock.getTime Clock.Monotonic
where
tSpecToDouble x = (s x) + (ns x)
ns x = (fromIntegral $ Clock.nsec x) * 1.0e-9
s x = fromIntegral $ Clock.sec x

runForAtLeast :: Double -> Int -> (Int -> IO a) -> IO (Double, Int, a)
runForAtLeast howLong initSeed act = loop initSeed (0::Int) =<< getTime
Expand Down
2 changes: 1 addition & 1 deletion criterion.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ library
aeson >= 0.3.2.12,
base < 5,
bytestring >= 0.9 && < 1.0,
clock >= 0.3 && < 0.4,
containers,
deepseq >= 1.1.0.0,
directory,
Expand All @@ -68,7 +69,6 @@ library
mwc-random >= 0.8.0.3,
parsec >= 3.1.0,
statistics >= 0.10.0.0,
time,
transformers,
vector >= 0.7.1,
vector-algorithms >= 0.4
Expand Down

0 comments on commit b6f657c

Please sign in to comment.