@@ -3,20 +3,22 @@
33
44import Streamly
55import qualified Streamly.Prelude as S
6+import Streamly.Internal.Data.Time.Clock (getTime, Clock(..))
7+import Streamly.Internal.Data.Time.Units
8+ (NanoSecond64, diffAbsTime64, fromRelTime64)
9+
610import Control.Concurrent
711import Control.Monad
8−import System.Clock
9−import Test.Hspec
1012import System.Random
13+import Test.Hspec
1114
1215durationShouldBe :: (Double, Double) -> IO () -> Expectation
1316durationShouldBe d@(tMin, tMax) action = do
1417 t0 <- getTime Monotonic
1518 action
1619 t1 <- getTime Monotonic
17− let t = fromIntegral (toNanoSecs (t1 - t0)) / 1e9
18− -- tMax = fromNanoSecs (round $ d*10^9*1.2)
19− -- tMin = fromNanoSecs (round $ d*10^9*0.8)
20+ let diff = fromRelTime64 (diffAbsTime64 t1 t0) :: NanoSecond64
21+ let t = fromIntegral diff / 1e9
2022 putStrLn $ "Expected: " <> show d <> " Took: " <> show t
2123 (t <= tMax && t >= tMin) `shouldBe` True
2224
@@ -50,7 +52,7 @@ measureRate' desc t buffers threads rval consumerDelay producerDelay expectedRan
5052 <> ", consumer latency: " <> show consumerDelay
5153 <> ", producer latency: " <> show producerDelay)
5254 $ durationShouldBe expectedRange $
53− runStream
55+ S.drain
5456 $ (if consumerDelay > 0
5557 then S.mapM $ \x ->
5658 threadDelay (toMicroSecs consumerDelay) >> return x