Created
February 3, 2018 18:39
-
-
Save bgamari/53177446b74219bae3227d2cca33b92a to your computer and use it in GitHub Desktop.
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
import Control.Concurrent | |
import Control.Concurrent.STM | |
import Criterion.Main | |
import Data.IORef | |
main = do | |
mv <- newMVar () | |
tv <- newTMVarIO () | |
ir <- newIORef () | |
defaultMain $ | |
[ bgroup "reading" | |
[ bench "MVar" $ whnfIO $ readMVar mv | |
, bench "TMVar" $ whnfIO $ atomically $ readTMVar tv | |
, bench "IORef" $ whnfIO $ readIORef ir | |
] | |
, bgroup "take/put" | |
[ bench "TMVar" $ whnfIO $ atomically (takeTMVar tv) >> atomically (putTMVar tv ()) | |
, bench "MVar" $ whnfIO $ takeMVar mv >> putMVar mv () | |
] | |
] |
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
benchmarking reading/MVar | |
time 1.663 ns (1.662 ns .. 1.663 ns) | |
1.000 R² (1.000 R² .. 1.000 R²) | |
mean 1.660 ns (1.658 ns .. 1.663 ns) | |
std dev 7.061 ps (2.594 ps .. 14.45 ps) | |
benchmarking reading/TMVar | |
time 22.57 ns (22.54 ns .. 22.61 ns) | |
1.000 R² (1.000 R² .. 1.000 R²) | |
mean 22.50 ns (22.48 ns .. 22.53 ns) | |
std dev 80.60 ps (66.98 ps .. 98.68 ps) | |
benchmarking reading/IORef | |
time 1.337 ns (1.337 ns .. 1.337 ns) | |
1.000 R² (1.000 R² .. 1.000 R²) | |
mean 1.334 ns (1.333 ns .. 1.335 ns) | |
std dev 2.163 ps (1.630 ps .. 2.890 ps) | |
benchmarking take/put/TMVar | |
time 54.18 ns (54.16 ns .. 54.20 ns) | |
1.000 R² (1.000 R² .. 1.000 R²) | |
mean 54.07 ns (54.04 ns .. 54.09 ns) | |
std dev 92.54 ps (76.48 ps .. 117.0 ps) | |
benchmarking take/put/MVar | |
time 3.789 ns (3.788 ns .. 3.790 ns) | |
1.000 R² (1.000 R² .. 1.000 R²) | |
mean 3.781 ns (3.779 ns .. 3.783 ns) | |
std dev 5.546 ps (4.523 ps .. 6.762 ps) | |
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
benchmarking reading/MVar | |
time 1.683 ns (1.682 ns .. 1.683 ns) | |
1.000 R² (1.000 R² .. 1.000 R²) | |
mean 1.679 ns (1.678 ns .. 1.680 ns) | |
std dev 3.049 ps (2.444 ps .. 3.893 ps) | |
benchmarking reading/TMVar | |
time 28.28 ns (27.96 ns .. 28.57 ns) | |
0.999 R² (0.999 R² .. 1.000 R²) | |
mean 28.16 ns (27.98 ns .. 28.35 ns) | |
std dev 638.4 ps (595.3 ps .. 698.5 ps) | |
variance introduced by outliers: 35% (moderately inflated) | |
benchmarking reading/IORef | |
time 1.334 ns (1.334 ns .. 1.335 ns) | |
1.000 R² (1.000 R² .. 1.000 R²) | |
mean 1.331 ns (1.331 ns .. 1.332 ns) | |
std dev 1.840 ps (1.552 ps .. 2.173 ps) | |
benchmarking take/put/TMVar | |
time 80.83 ns (80.82 ns .. 80.85 ns) | |
1.000 R² (1.000 R² .. 1.000 R²) | |
mean 80.63 ns (80.59 ns .. 80.68 ns) | |
std dev 153.0 ps (123.1 ps .. 211.7 ps) | |
benchmarking take/put/MVar | |
time 4.672 ns (4.671 ns .. 4.674 ns) | |
1.000 R² (1.000 R² .. 1.000 R²) | |
mean 4.662 ns (4.660 ns .. 4.665 ns) | |
std dev 7.891 ps (5.973 ps .. 11.45 ps) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment