forked from tamarin-prover/tamarin-prover
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix reporting of processing time (tamarin-prover#517)
Fixes a regression introduced in tamarin-prover#484 where the processing time was incorrectly measured due to the missing full evaluation of the IO action. Additionally, the precission of the reported time is now set to 2.
- Loading branch information
1 parent
df1aa9f
commit a810774
Showing
2 changed files
with
28 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
-- | | ||
-- Copyright : (c) 2011 Simon Meier | ||
-- Copyright : (c) 2011 Simon Meier, 2022 Kevin Morio | ||
-- License : GPL v3 (see LICENSE) | ||
-- | ||
-- Maintainer : Simon Meier <iridcode@gmail.com> | ||
-- Portability : GHC only | ||
-- | ||
-- A simple module for timing IO action. | ||
-- A simple module for timing IO actions and evaluation of values. | ||
module System.Timing ( | ||
timed | ||
, timed_ | ||
timedIO | ||
, timed | ||
) where | ||
|
||
import Control.Monad | ||
import Data.Time.Clock | ||
import Data.Time.Clock ( diffUTCTime, getCurrentTime, NominalDiffTime ) | ||
import GHC.IO (unsafePerformIO) | ||
import Control.DeepSeq ( NFData, deepseq ) | ||
|
||
-- | Execute an IO action and return its result plus the time it took to execute it. | ||
timed :: IO a -> IO (a, NominalDiffTime) | ||
timed io = do | ||
t0 <- getCurrentTime | ||
x <- io | ||
t1 <- getCurrentTime | ||
return (x, diffUTCTime t1 t0) | ||
-- | Fully evaluate an IO action and measure its execution time. | ||
timedIO :: NFData a => IO a -> IO (a, NominalDiffTime) | ||
timedIO mx = do | ||
t0 <- getCurrentTime | ||
val <- mx | ||
t1 <- val `deepseq` getCurrentTime | ||
let measure = t1 `diffUTCTime` t0 | ||
return (val, measure) | ||
|
||
-- | Execute an IO action and return the time it took to execute it. | ||
timed_ :: IO a -> IO NominalDiffTime | ||
timed_ = (snd `liftM`) . timed | ||
-- | Fully evaluate a value and measure its execution time. | ||
timed :: NFData a => a -> (a, NominalDiffTime) | ||
timed x = | ||
let measure = unsafePerformIO $ do | ||
t0 <- getCurrentTime | ||
t1 <- x `deepseq` getCurrentTime | ||
return (t1 `diffUTCTime` t0) | ||
in (x, measure) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters