shrub/pkg/king/app/TryTimers.hs

52 lines
1.3 KiB
Haskell
Raw Normal View History

2019-08-13 07:57:30 +03:00
module TryTimers where
2019-05-08 21:47:20 +03:00
2019-08-13 07:57:30 +03:00
{-
2019-05-08 21:47:20 +03:00
import Prelude
import Control.Lens
import Control.Concurrent.MVar (takeMVar, putMVar, newEmptyMVar)
import Control.Concurrent (threadDelay, forkIO)
import Control.Monad (replicateM_, when)
import qualified Urbit.Timer as Timer
import qualified Urbit.Behn as Behn
import qualified Urbit.Time as Time
import qualified Data.Time.Clock.System as Sys
2019-05-08 21:47:20 +03:00
--------------------------------------------------------------------------------
benchTimer :: Timer.Timer -> IO ()
benchTimer timer = do
now <- Sys.getSystemTime
let wen = case now of Sys.MkSystemTime s ns ->
Sys.MkSystemTime s (ns + 5_000_000)
v <- newEmptyMVar
Timer.start timer wen (putMVar v ())
takeMVar v
end <- Timer.getSystemTime
print (Timer.sysTimeGapMicroSecs wen end)
2019-05-09 02:57:34 +03:00
bench :: Behn.Behn -> IO ()
2019-05-08 21:47:20 +03:00
bench behn = do
now <- Time.now
let wen = Time.addGap now (5 ^. from Time.milliSecs)
2019-05-09 02:57:34 +03:00
Behn.doze behn (Just wen)
() <- Behn.wait behn
2019-05-08 21:47:20 +03:00
aft <- Time.now
print (Time.gap wen aft ^. Time.microSecs)
2019-05-08 21:47:20 +03:00
main :: IO ()
main = do
behn <- Behn.init
timer <- Timer.init
putStrLn "<benchTimer>"
replicateM_ 10 (benchTimer timer)
putStrLn "</benchTimer>"
2019-05-08 21:47:20 +03:00
2019-05-09 02:57:34 +03:00
putStrLn "<bench>"
replicateM_ 10 (bench behn)
2019-05-09 02:57:34 +03:00
putStrLn "</bench>"
2019-08-13 07:57:30 +03:00
-}