1{-# LANGUAGE RankNTypes #-}
4-- Copyright : (c) 2018 Harendra Kumar
7-- Maintainer : streamly@composewell.com
9import Control.Concurrent
10import Control.Monad (when)
15import qualified Streamly.Prelude as S
17-------------------------------------------------------------------------------
19-------------------------------------------------------------------------------
21-- Single work item yielded per thread
24 => Int -> Int -> Int -> (t IO Int -> SerialT IO Int) -> IO ()
25append buflen tcount d t =
26 let work = (\i -> when (d /= 0) (threadDelay d) >> return i)
31 $ S.fromFoldableM $ map work [1..tcount]
33-- Big stream of items yielded per thread
34{-# INLINE concated #-}
35concated :: Int -> Int -> Int -> Int -> (forall a. SerialT IO a -> SerialT IO a -> SerialT IO a) -> IO ()
36concated buflen threads d elems t =
37 let work = (\i -> (S.replicateM i ((when (d /= 0) (threadDelay d)) >> return i)))
42 $ S.concatMapWith t work
43 $ S.replicate threads elems
45appendGroup :: Int -> Int -> Int -> [Benchmark]
46appendGroup buflen threads delay =
47 [ -- bench "serial" $ nfIO $ append buflen threads delay serially
48 bench "ahead" $ nfIO $ append buflen threads delay aheadly
49 , bench "async" $ nfIO $ append buflen threads delay asyncly
50 , bench "wAsync" $ nfIO $ append buflen threads delay wAsyncly
51 , bench "parallel" $ nfIO $ append buflen threads delay parallely
54concatGroup :: Int -> Int -> Int -> Int -> [Benchmark]
55concatGroup buflen threads delay n =
56 [ bench "serial" $ nfIO $ concated buflen threads delay n serial
57 , bench "ahead" $ nfIO $ concated buflen threads delay n ahead
58 , bench "async" $ nfIO $ concated buflen threads delay n async
59 , bench "wAsync" $ nfIO $ concated buflen threads delay n wAsync
60 , bench "parallel" $ nfIO $ concated buflen threads delay n parallel
65 defaultMainWith (defaultConfig
69 , includeFirstIter = True
73 [ -- bgroup "append/buf-1-threads-10k-0sec" (appendGroup 1 10000 0)
74 -- , bgroup "append/buf-100-threads-100k-0sec" (appendGroup 100 100000 0)
75 bgroup "append/buf-10k-threads-10k-5sec" (appendGroup 10000 10000 5000000)
76 -- bgroup "concat/buf-1-threads-100k-count-1" (concatGroup 1 100000 0 1)
77 -- bgroup "concat/buf-1-threads-1-count-10m" (concatGroup 1 1 0 10000000)
78 , bgroup "concat/buf-100-threads-100-count-500k" (concatGroup 100 100 0 500000)
80 , bgroup "forkIO-5000ms-10k" $
81 let delay = threadDelay 5000000
84 work i = delay >> return i
86 [ bench "discard" $ nfIO $ do
87 mapM_ (\i -> forkIO $ work i >> return ()) list
89 , bench "collect" $ nfIO $ do
91 mapM_ (\i -> forkIO $ work i >>=
92 \j -> atomicModifyIORef ref $ \xs -> (j : xs, ())) list
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list