@@ -3,20 +3,22 @@
4import Streamly
4import Streamly
5import qualified Streamly.Prelude as S
5import 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)
6import Control.Concurrent
10import Control.Concurrent
7import Control.Monad
11import Control.Monad
10import System.Random
12import System.Random
12durationShouldBe :: (Double, Double) -> IO () -> Expectation
15durationShouldBe :: (Double, Double) -> IO () -> Expectation
13durationShouldBe d@(tMin, tMax) action = do
16durationShouldBe d@(tMin, tMax) action = do
14 t0 <- getTime Monotonic
17 t0 <- getTime Monotonic
16 t1 <- getTime Monotonic
19 t1 <- getTime Monotonic
17− let t = fromIntegral (toNanoSecs (t1 - t0)) / 1e9
20+ let diff = fromRelTime64 (diffAbsTime64 t1 t0) :: NanoSecond64
18− -- tMax = fromNanoSecs (round $ d*10^9*1.2)
21+ let t = fromIntegral diff / 1e9
19− -- tMin = fromNanoSecs (round $ d*10^9*0.8)
20 putStrLn $ "Expected: " <> show d <> " Took: " <> show t
22 putStrLn $ "Expected: " <> show d <> " Took: " <> show t
21 (t <= tMax && t >= tMin) `shouldBe` True
23 (t <= tMax && t >= tMin) `shouldBe` True
@@ -50,7 +52,7 @@ measureRate' desc t buffers threads rval consumerDelay producerDelay expectedRan
50 <> ", consumer latency: " <> show consumerDelay
52 <> ", consumer latency: " <> show consumerDelay
51 <> ", producer latency: " <> show producerDelay)
53 <> ", producer latency: " <> show producerDelay)
52 $ durationShouldBe expectedRange $
54 $ durationShouldBe expectedRange $
54 $ (if consumerDelay > 0
56 $ (if consumerDelay > 0
55 then S.mapM $ \x ->
57 then S.mapM $ \x ->
56 threadDelay (toMicroSecs consumerDelay) >> return x
58 threadDelay (toMicroSecs consumerDelay) >> return x