File tree 4 files changed +40
-4
lines changed
4 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 3
3
-- | Perform 100,000 atomic increments using 100 concurrent writers.
4
4
module Main where
5
5
6
+ import Prelude hiding (read )
7
+
6
8
import Control.Concurrent
7
9
import Control.Monad
10
+ import Criterion
11
+ import Criterion.Main (defaultMain )
12
+ import Data.Int (Int64 )
8
13
import System.Metrics.Counter
9
14
10
15
main :: IO ()
11
- main = do
16
+ main = defaultMain
17
+ [ bench " Increment counter with multiple writers" $
18
+ whnfIO incrementWithMultipleWriters
19
+ ]
20
+
21
+ incrementWithMultipleWriters :: IO Int64
22
+ incrementWithMultipleWriters = do
12
23
counter <- new
13
24
locks <- replicateM n newEmptyMVar
14
25
mapM_ (forkIO . work counter iters) locks
15
26
mapM_ takeMVar locks
27
+ total <- read counter
28
+ unless (fromIntegral total == n* iters) $
29
+ error " Incorrect count!"
30
+ pure total
16
31
where
17
32
n = 100
18
33
iters = 100000
Original file line number Diff line number Diff line change 4
4
-- writers.
5
5
module Main where
6
6
7
+ import Prelude hiding (read )
8
+
7
9
import Control.Concurrent
8
10
import Control.Monad
11
+ import Criterion
12
+ import Criterion.Main (defaultMain )
13
+ import Data.Int (Int64 )
9
14
import System.Metrics.Distribution
10
15
11
16
main :: IO ()
12
- main = do
17
+ main = defaultMain
18
+ [ bench " Add to distribution with multiple writers" $
19
+ whnfIO addWithMultipleWriters
20
+ ]
21
+
22
+ addWithMultipleWriters :: IO Int64
23
+ addWithMultipleWriters = do
13
24
distrib <- new
14
25
locks <- replicateM n newEmptyMVar
15
26
mapM_ (forkIO . work distrib iters) locks
16
27
mapM_ takeMVar locks
28
+ total <- count <$> read distrib
29
+ unless (fromIntegral total == n* iters) $
30
+ error " Incorrect count!"
31
+ pure total
17
32
where
18
33
n = 100
19
34
iters = 100000
Original file line number Diff line number Diff line change @@ -58,7 +58,8 @@ benchmark counter
58
58
type : exitcode-stdio-1.0
59
59
build-depends :
60
60
base,
61
- ekg-core
61
+ ekg-core,
62
+ criterion ^>= 1.5.9.0
62
63
default-language : Haskell2010
63
64
hs-source-dirs : benchmarks
64
65
ghc-options : -O2 -threaded -Wall
@@ -68,7 +69,8 @@ benchmark distribution
68
69
type : exitcode-stdio-1.0
69
70
build-depends :
70
71
base,
71
- ekg-core
72
+ ekg-core,
73
+ criterion ^>= 1.5.9.0
72
74
default-language : Haskell2010
73
75
hs-source-dirs : benchmarks
74
76
ghc-options : -O2 -threaded -Wall
Original file line number Diff line number Diff line change 4
4
component : " lib:ekg-core"
5
5
- path : " ./test"
6
6
component : " test:ekg-core-test"
7
+ - path : " ./benchmarks"
8
+ component : " bench:counter"
9
+ - path : " ./benchmarks"
10
+ component : " bench:distribution"
You can’t perform that action at this time.
0 commit comments