Created
June 24, 2013 20:18
-
-
Save chemist/5853246 to your computer and use it in GitHub Desktop.
Performance test MVar vs TMVar vs IORef.
Just read.
This file contains hidden or 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
~/develop/bench -$ cat Main.hs iMac-Alexej@chemist :) | |
import Control.Concurrent | |
import Control.Concurrent.STM | |
import Criterion.Main | |
import Data.IORef | |
main = do | |
mv <- newMVar () | |
tv <- newTMVarIO () | |
ir <- newIORef () | |
defaultMain [ bench "MVar" (readMVar mv) | |
, bench "TMVar" (atomically $ readTMVar tv) | |
, bench "IORef" (readIORef ir) | |
] | |
~/develop/bench -$ ghc -O2 -threaded Main.hs -o mv-tm-ir iMac-Alexej@chemist :) | |
~/develop/bench -$ ./mv-tm-ir iMac-Alexej@chemist :) | |
warming up | |
estimating clock resolution... | |
mean is 1.314451 us (640001 iterations) | |
found 3421 outliers among 639999 samples (0.5%) | |
2748 (0.4%) high severe | |
estimating cost of a clock call... | |
mean is 49.09204 ns (9 iterations) | |
found 2 outliers among 9 samples (22.2%) | |
1 (11.1%) high mild | |
1 (11.1%) high severe | |
benchmarking MVar | |
mean: 40.45142 ns, lb 40.01889 ns, ub 40.83322 ns, ci 0.950 | |
std dev: 2.081636 ns, lb 1.655347 ns, ub 3.136299 ns, ci 0.950 | |
found 11 outliers among 100 samples (11.0%) | |
1 (1.0%) low severe | |
10 (10.0%) high mild | |
variance introduced by outliers: 49.465% | |
variance is moderately inflated by outliers | |
benchmarking TMVar | |
mean: 59.49208 ns, lb 59.13058 ns, ub 59.94610 ns, ci 0.950 | |
std dev: 2.065702 ns, lb 1.718641 ns, ub 2.541805 ns, ci 0.950 | |
found 5 outliers among 100 samples (5.0%) | |
5 (5.0%) high mild | |
variance introduced by outliers: 30.673% | |
variance is moderately inflated by outliers | |
benchmarking IORef | |
mean: 4.987461 ns, lb 4.976263 ns, ub 5.002600 ns, ci 0.950 | |
std dev: 66.13710 ps, lb 52.75414 ps, ub 84.57218 ps, ci 0.950 | |
found 20 outliers among 100 samples (20.0%) | |
13 (13.0%) high mild | |
7 (7.0%) high severe | |
variance introduced by outliers: 6.565% | |
variance is slightly inflated by outliers | |
~/develop/bench -$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment