urbit/pkg/hair/app/vere/Main.hs

66 lines
1.6 KiB
Haskell
Raw Normal View History

2019-05-08 21:47:20 +03:00
module Main where
import Prelude
import Control.Lens
2019-05-08 23:51:04 +03:00
import Control.Concurrent.MVar
import Control.Concurrent (threadDelay, forkIO)
import Control.Monad (replicateM_, when)
2019-05-08 21:47:20 +03:00
import Data.LargeWord (Word128, LargeKey(..))
import qualified Urbit.Behn as Behn
import qualified Urbit.Time as Time
--------------------------------------------------------------------------------
2019-05-08 23:51:04 +03:00
threadDelayBench :: IO Time.Gap
threadDelayBench = do
before <- Time.now
mvar :: MVar () <- newEmptyMVar
forkIO $ do threadDelay 100
putMVar mvar ()
takeMVar mvar
after <- Time.now
pure (Time.gap before after)
simpleBench :: Behn.Behn -> IO Time.Gap
simpleBench behn = do
before <- Time.now
target <- pure (Time.addGap before (10 ^. from Time.milliSecs))
_ <- Behn.doze behn (Just target)
after <- Behn.wait behn >> Time.now
pure (Time.gap target after)
2019-05-08 21:47:20 +03:00
bench :: Behn.Behn -> IO (Time.Wen, Time.Wen, Time.Wen)
bench behn = do
now <- Time.now
print (now ^. Time.wenUtcTime)
2019-05-08 23:51:04 +03:00
Behn.doze behn (Just (Time.addGap now (2 ^. from Time.milliSecs)))
2019-05-08 21:47:20 +03:00
wen <- Behn.wait behn
aft <- Time.now
pure (now, wen, aft)
main :: IO ()
main = do
behn <- Behn.init
2019-05-08 23:51:04 +03:00
replicateM_ 5 (threadDelayBench >>= (print . view Time.microSecs))
putStrLn "</threadDelayBench>"
replicateM_ 5 (simpleBench behn >>= (print . view Time.microSecs))
2019-05-08 21:47:20 +03:00
(x1,y1,z1) <- bench behn
(x2,y2,z2) <- bench behn
(x3,y3,z3) <- bench behn
putStrLn "----"
print (Time.gap y1 z1 ^. Time.milliSecs)
print (Time.gap y2 z2 ^. Time.milliSecs)
print (Time.gap y3 z3 ^. Time.milliSecs)