chronos 1.0.9 → 1.1
raw patch · 2 files changed
+35/−2 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Chronos: stopwatchWith :: Clock -> IO a -> IO (Timespan, a)
- Chronos: stopwatchWith_ :: Clock -> IO a -> IO Timespan
Files
- chronos.cabal +3/−2
- src/Chronos.hs +32/−0
chronos.cabal view
@@ -2,7 +2,7 @@ name: chronos version:- 1.0.9+ 1.1 synopsis: A performant time library description:@@ -61,7 +61,6 @@ , attoparsec >= 0.13 && < 0.14 , base >= 4.9 && < 5 , bytestring >= 0.10 && < 0.11- , clock >= 0.7 && < 0.9 , hashable >= 1.2 && < 1.4 , primitive >= 0.6.4 && < 0.8 , semigroups >= 0.16 && < 0.20@@ -70,6 +69,8 @@ , vector >= 0.11 && < 0.13 if os(windows) build-depends: Win32 >= 2.2 && < 2.9+ if impl(ghc < 8.4)+ build-depends: clock >= 0.7 && < 0.9 default-language: Haskell2010 c-sources:
src/Chronos.hs view
@@ -5,6 +5,7 @@ , GeneralizedNewtypeDeriving , MultiParamTypeClasses , OverloadedStrings+ , RecordWildCards , ScopedTypeVariables , TypeFamilies , TypeInType@@ -46,8 +47,10 @@ -- ** Duration , stopwatch , stopwatch_+#if !MIN_VERSION_base(4,11,0) , stopwatchWith , stopwatchWith_+#endif -- ** Construction , datetimeFromYmdhms , timeFromYmdhms@@ -276,7 +279,11 @@ import qualified Data.Vector.Generic.Mutable as MGVector import qualified Data.Vector.Primitive as PVector import qualified Data.Vector.Unboxed as UVector+#if MIN_VERSION_base(4,11,0)+import GHC.Clock (getMonotonicTimeNSec)+#else import qualified System.Clock as CLK+#endif #ifdef mingw32_HOST_OS import System.Win32.Time (SYSTEMTIME(..))@@ -486,10 +493,32 @@ epoch :: Time epoch = Time 0 +#if MIN_VERSION_base(4,11,0) -- | Measures the time it takes to run an action and evaluate -- its result to WHNF. This measurement uses a monotonic clock -- instead of the standard system clock. stopwatch :: IO a -> IO (Timespan, a)+stopwatch action = do+ start <- getMonotonicTimeNSec+ a <- action >>= evaluate+ end <- getMonotonicTimeNSec+ pure ((Timespan (fromIntegral (end - start))), a)++-- | Measures the time it takes to run an action. The result+-- is discarded. This measurement uses a monotonic clock+-- instead of the standard system clock.+stopwatch_ :: IO a -> IO Timespan+stopwatch_ action = do+ start <- getMonotonicTimeNSec+ _ <- action+ end <- getMonotonicTimeNSec+ pure (Timespan (fromIntegral (end - start)))+#else++-- | Measures the time it takes to run an action and evaluate+-- its result to WHNF. This measurement uses a monotonic clock+-- instead of the standard system clock.+stopwatch :: IO a -> IO (Timespan, a) stopwatch = stopwatchWith CLK.Monotonic -- | Measures the time it takes to run an action. The result@@ -507,6 +536,7 @@ a <- action >>= evaluate end <- CLK.getTime c pure (timeSpecToTimespan (CLK.diffTimeSpec end start),a)+{-# DEPRECATED stopwatchWith "stopwatchWith will be removed in a future majour version" #-} -- | Variant of 'stopwatch_' that accepts a clock type. stopwatchWith_ :: CLK.Clock -> IO a -> IO Timespan@@ -515,9 +545,11 @@ _ <- action end <- CLK.getTime c pure (timeSpecToTimespan (CLK.diffTimeSpec end start))+{-# DEPRECATED stopwatchWith_ "stopwatchWith_ will be removed in a future majour version" #-} timeSpecToTimespan :: CLK.TimeSpec -> Timespan timeSpecToTimespan (CLK.TimeSpec s ns) = Timespan (s * 1000000000 + ns)+#endif -- UtcTime. Used internally only. data UtcTime = UtcTime