-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple criterion benchmark suite
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |