-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sleep.hs
52 lines (40 loc) · 1.62 KB
/
Sleep.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE OverloadedStrings #-}
module LibMain.Sleep where
import Control.Monad
import Control.Concurrent
import System.Environment
import Pipeline
------------------------------------------------------------------------
iTERATIONS :: Int
iTERATIONS = 10000
sLEEP_MICROS :: Int
sLEEP_MICROS = 25
------------------------------------------------------------------------
sleepP :: P (Input ()) (Output ())
sleepP = TransformM "sleep1" (const (Output <$> threadDelay sLEEP_MICROS)) :&&&
TransformM "sleep2" (const (Output <$> threadDelay sLEEP_MICROS)) :>>>
TransformM "sleep3" (const (Output <$> threadDelay sLEEP_MICROS)) :>>>
TransformM "sleep4" (const (Output <$> threadDelay sLEEP_MICROS))
sleepPSharded :: P (Input ()) (Sharded (Output ()))
sleepPSharded = Shard sleepP
runDisruptorSleep :: EnableMetrics -> IO ()
runDisruptorSleep enableMetrics =
void (runPList sleepP enableMetrics (replicate iTERATIONS ()))
{-# INLINE runDisruptorSleep #-}
runDisruptorSleepSharded :: EnableMetrics -> IO ()
runDisruptorSleepSharded enableMetrics =
void (runPListSharded sleepPSharded enableMetrics (replicate iTERATIONS ()))
{-# INLINE runDisruptorSleepSharded #-}
main :: IO ()
main = do
args <- getArgs
let sharded = any ((==) "--sharded") args
enableMetrics = any (\arg -> arg == "--metrics" ||
arg == "--enable-metrics") args
if sharded
then do
putStrLn "Running sharded sleep on Disruptor pipeline"
timeIt $ runDisruptorSleepSharded enableMetrics
else do
putStrLn "Running sleep on Disruptor pipeline"
timeIt $ runDisruptorSleep enableMetrics