Skip to content

Commit

Permalink
Add a simple criterion benchmark suite
Browse files Browse the repository at this point in the history
  • Loading branch information
rrnewton committed Oct 24, 2014
1 parent 589fe94 commit 0f844b3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
39 changes: 39 additions & 0 deletions monad-par/bench/Bench.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{-# LANGUAGE RankNTypes, BangPatterns #-}

module Main where

import Control.Monad.Par
import Control.Monad (forM_)
import Criterion.Main
import Criterion.Types (Benchmarkable(Benchmarkable))


-- | Helper for benchmarking par-monad actions:
benchPar :: Par () -> Benchmarkable
benchPar par = Benchmarkable $ \ iters ->
runParIO $
for_ 1 (fromIntegral iters) $ \_ -> do
par
{-# INLINE benchPar #-}

main = defaultMain [
bgroup "monad-par"
[ bench "NOOP" $ benchPar (return ())
, bench "fork" $ benchPar (fork (return ()))
, bench "new" $ benchPar (do new; return ())
, bench "newFull" $ benchPar (do iv <- newFull (3::Int); return ())
, bench "newFull-get" $ benchPar (do iv <- newFull (3::Int); get iv; return ())
, bench "new-put" $ benchPar (do iv <- new; put iv (3::Int); return ())
, bench "new-put-get" $ benchPar (do iv <- new; put iv (3::Int); get iv; return ())
, bench "new-fork-get" $ benchPar (do iv <- new; fork (put iv (3::Int)); get iv; return ())
]
]

-- My own forM for inclusive numeric ranges (not requiring deforestation optimizations).
{-# INLINE for_ #-}
for_ :: Monad m => Int -> Int -> (Int -> m ()) -> m ()
for_ start end _fn | start > end = error "for_: start is greater than end"
for_ start end fn = loop start
where
loop !i | i > end = return ()
| otherwise = do fn i; loop (i+1)
7 changes: 7 additions & 0 deletions monad-par/bench/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


REPORTS= -o report_monadpar.html --csv=report_monadpar.csv

bench:
cabal install --bindir=. --program-suffix=.exe --ghc-options="-ddump-simpl -ddump-to-file"
./bench-monad-par.exe -v2 --regress=allocated:iters $(REPORTS) +RTS -T -s -RTS
19 changes: 19 additions & 0 deletions monad-par/bench/bench-monad-par.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

-- | This is split out from the parent package only to break the
-- dependency cycle.

Name: bench-monad-par
Version: 0.0.0.1
Cabal-version: >=1.8
Build-type: Simple
Executable bench-monad-par
main-is: Bench.hs
build-depends: monad-par
build-depends: base >= 4.6 && <= 4.8
-- , containers >= 0.5
-- , vector >=0.10
-- , random
build-depends: criterion >= 1.0

-- For we duplicate these flag-dependent options:
ghc-options: -O2 -threaded -rtsopts -with-rtsopts=-N4

0 comments on commit 0f844b3

Please sign in to comment.