Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Machines benchmark modified to include streaming https://github.com/ekmett/machines/blob/master/benchmarks/Benchmarks.hs
{-#LANGUAGE NoMonomorphismRestriction #-}
module Main (main) where
import Control.Monad (void)
import Control.Monad.Identity
import Criterion.Main
import qualified Data.Conduit as C
import qualified Data.Conduit.Combinators as CC
import qualified Data.Conduit.List as C
import qualified Data.Machine as M
import qualified Pipes as P
import qualified Pipes.Prelude as P
import qualified Streaming.Prelude as S
import Streaming (Of (..), Stream)
value :: Int
value = 1000000
drainS :: (Stream (Of Int) Identity () -> Stream (Of o) Identity ()) -> ()
drainS p = runIdentity $ S.effects $ p sourceS
drainM :: M.ProcessT Identity Int o -> ()
drainM m = runIdentity $ M.runT_ (sourceM M.~> m)
drainP :: P.Proxy () Int () a Identity () -> ()
drainP p = runIdentity $ P.runEffect $ P.for (sourceP P.>-> p) P.discard
drainC :: C.Conduit Int Identity a -> ()
drainC c = runIdentity $ (sourceC C.$= c) C.$$ C.sinkNull
drainSC :: C.Sink Int Identity b -> b
drainSC c = runIdentity $ sourceC C.$$ c
sourceM = M.enumerateFromTo 1 value
sourceC = C.enumFromTo 1 value
sourceP = P.each [1..value]
sourceS = S.take value $ S.enumFrom 1
main :: IO ()
main =
defaultMain
[ bgroup "map"
[ bench "streaming" $ whnf drainS (S.map (+1))
, bench "conduit" $ whnf drainC (C.map (+1))
, bench "pipes" $ whnf drainP (P.map (+1))
, bench "machines" $ whnf drainM (M.auto (+1))
]
, bgroup "drop"
[ bench "streaming" $ whnf drainS (S.drop value)
, bench "conduit" $ whnf drainC (C.drop value)
, bench "pipes" $ whnf drainP (P.drop value)
, bench "machines" $ whnf drainM (M.dropping value)
]
, bgroup "dropWhile"
[ bench "streaming" $ whnf drainS (S.dropWhile (<= value))
, bench "conduit" $ whnf drainC (CC.dropWhile (<= value))
, bench "pipes" $ whnf drainP (P.dropWhile (<= value))
, bench "machines" $ whnf drainM (M.droppingWhile (<= value))
]
, bgroup "scan"
[ bench "streaming" $ whnf drainS (S.scan (+) 0 id)
, bench "conduit" $ whnf drainC (CC.scanl (+) 0)
, bench "pipes" $ whnf drainP (P.scan (+) 0 id)
, bench "machines" $ whnf drainM (M.scan (+) 0)
]
, bgroup "take"
[ bench "streaming" $ whnf drainS (S.take value)
, bench "conduit" $ whnf drainC (C.isolate value)
, bench "pipes" $ whnf drainP (P.take value)
, bench "machines" $ whnf drainM (M.taking value)
]
, bgroup "takeWhile"
[ bench "streaming" $ whnf drainS (S.takeWhile (<= value))
, bench "conduit" $ whnf drainC (CC.takeWhile (<= value) C.=$= C.sinkNull)
, bench "pipes" $ whnf drainP (P.takeWhile (<= value))
, bench "machines" $ whnf drainM (M.takingWhile (<= value))
]
]
@michaelt

This comment has been minimized.

Copy link
Owner Author

michaelt commented Nov 2, 2015

benchmarking map/streaming
time                 15.76 ms   (15.52 ms .. 15.99 ms)
                     0.998 R?   (0.997 R? .. 0.999 R?)
mean                 16.02 ms   (15.88 ms .. 16.18 ms)
std dev              395.9 ?s   (309.4 ?s .. 510.3 ?s)

benchmarking map/conduit
time                 30.85 ms   (30.21 ms .. 31.52 ms)
                     0.998 R?   (0.996 R? .. 0.999 R?)
mean                 30.71 ms   (30.38 ms .. 31.05 ms)
std dev              725.3 ?s   (565.9 ?s .. 981.9 ?s)

benchmarking map/pipes
time                 53.74 ms   (53.10 ms .. 54.31 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 54.04 ms   (53.70 ms .. 54.36 ms)
std dev              621.5 ?s   (446.2 ?s .. 919.9 ?s)

benchmarking map/machines
time                 154.4 ms   (152.0 ms .. 158.8 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 155.9 ms   (154.8 ms .. 157.2 ms)
std dev              1.515 ms   (880.5 ?s .. 2.103 ms)
variance introduced by outliers: 12% (moderately inflated)

benchmarking drop/streaming
time                 7.003 ms   (6.907 ms .. 7.080 ms)
                     0.999 R?   (0.998 R? .. 1.000 R?)
mean                 7.026 ms   (6.979 ms .. 7.089 ms)
std dev              165.9 ?s   (126.5 ?s .. 232.8 ?s)

benchmarking drop/conduit
time                 26.56 ms   (26.31 ms .. 26.79 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 26.93 ms   (26.78 ms .. 27.22 ms)
std dev              439.4 ?s   (231.5 ?s .. 686.7 ?s)

benchmarking drop/pipes
time                 43.64 ms   (42.48 ms .. 45.46 ms)
                     0.995 R?   (0.983 R? .. 1.000 R?)
mean                 44.91 ms   (44.38 ms .. 46.17 ms)
std dev              1.406 ms   (720.3 ?s .. 2.436 ms)

benchmarking drop/machines
time                 108.9 ms   (106.7 ms .. 110.2 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 111.1 ms   (109.8 ms .. 113.6 ms)
std dev              2.671 ms   (1.345 ms .. 4.108 ms)

benchmarking dropWhile/streaming
time                 20.47 ms   (19.99 ms .. 20.95 ms)
                     0.998 R?   (0.997 R? .. 1.000 R?)
mean                 20.15 ms   (19.99 ms .. 20.33 ms)
std dev              387.7 ?s   (288.4 ?s .. 537.4 ?s)

benchmarking dropWhile/conduit
time                 30.57 ms   (30.14 ms .. 31.14 ms)
                     0.999 R?   (0.998 R? .. 1.000 R?)
mean                 30.36 ms   (30.04 ms .. 30.66 ms)
std dev              663.7 ?s   (521.7 ?s .. 851.0 ?s)

benchmarking dropWhile/pipes
time                 25.64 ms   (25.05 ms .. 26.17 ms)
                     0.998 R?   (0.996 R? .. 0.999 R?)
mean                 26.73 ms   (26.39 ms .. 27.10 ms)
std dev              740.7 ?s   (612.5 ?s .. 914.1 ?s)

benchmarking dropWhile/machines
time                 78.24 ms   (77.26 ms .. 79.81 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 78.88 ms   (78.33 ms .. 79.39 ms)
std dev              856.3 ?s   (710.8 ?s .. 1.051 ms)

benchmarking scan/streaming
time                 17.41 ms   (17.06 ms .. 17.71 ms)
                     0.999 R?   (0.998 R? .. 1.000 R?)
mean                 17.64 ms   (17.48 ms .. 18.12 ms)
std dev              618.3 ?s   (218.3 ?s .. 1.192 ms)
variance introduced by outliers: 12% (moderately inflated)

benchmarking scan/conduit
time                 61.32 ms   (60.58 ms .. 62.19 ms)
                     0.999 R?   (0.998 R? .. 1.000 R?)
mean                 60.72 ms   (60.02 ms .. 61.41 ms)
std dev              1.237 ms   (827.8 ?s .. 1.938 ms)

benchmarking scan/pipes
time                 60.84 ms   (59.68 ms .. 61.76 ms)
                     0.999 R?   (0.999 R? .. 1.000 R?)
mean                 61.06 ms   (60.48 ms .. 61.54 ms)
std dev              934.5 ?s   (724.4 ?s .. 1.289 ms)

benchmarking scan/machines
time                 215.1 ms   (196.3 ms .. 243.8 ms)
                     0.993 R?   (0.967 R? .. 1.000 R?)
mean                 214.8 ms   (209.9 ms .. 226.8 ms)
std dev              9.518 ms   (292.8 ?s .. 13.12 ms)
variance introduced by outliers: 14% (moderately inflated)

benchmarking take/streaming
time                 15.08 ms   (14.92 ms .. 15.28 ms)
                     0.999 R?   (0.998 R? .. 1.000 R?)
mean                 15.15 ms   (15.03 ms .. 15.28 ms)
std dev              305.9 ?s   (246.4 ?s .. 384.0 ?s)

benchmarking take/conduit
time                 45.38 ms   (44.57 ms .. 46.45 ms)
                     0.999 R?   (0.997 R? .. 1.000 R?)
mean                 45.73 ms   (45.37 ms .. 46.24 ms)
std dev              818.9 ?s   (578.1 ?s .. 1.156 ms)

benchmarking take/pipes
time                 84.44 ms   (78.23 ms .. 91.36 ms)
                     0.990 R?   (0.980 R? .. 1.000 R?)
mean                 79.92 ms   (78.66 ms .. 83.33 ms)
std dev              3.333 ms   (757.1 ?s .. 5.530 ms)

benchmarking take/machines
time                 210.3 ms   (203.8 ms .. 217.1 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 213.2 ms   (211.4 ms .. 215.1 ms)
std dev              2.321 ms   (1.417 ms .. 2.577 ms)
variance introduced by outliers: 14% (moderately inflated)

benchmarking takeWhile/streaming
time                 15.85 ms   (15.62 ms .. 16.10 ms)
                     0.998 R?   (0.993 R? .. 1.000 R?)
mean                 15.80 ms   (15.63 ms .. 16.18 ms)
std dev              588.1 ?s   (308.1 ?s .. 1.012 ms)
variance introduced by outliers: 12% (moderately inflated)

benchmarking takeWhile/conduit
time                 48.87 ms   (46.97 ms .. 50.13 ms)
                     0.997 R?   (0.992 R? .. 1.000 R?)
mean                 51.11 ms   (49.98 ms .. 55.21 ms)
std dev              3.513 ms   (543.9 ?s .. 6.228 ms)
variance introduced by outliers: 22% (moderately inflated)

benchmarking takeWhile/pipes
time                 51.96 ms   (51.63 ms .. 52.27 ms)
                     1.000 R?   (1.000 R? .. 1.000 R?)
mean                 52.14 ms   (51.86 ms .. 52.81 ms)
std dev              743.7 ?s   (336.2 ?s .. 1.250 ms)

benchmarking takeWhile/machines
time                 185.9 ms   (181.5 ms .. 190.0 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 186.0 ms   (184.8 ms .. 187.3 ms)
std dev              1.568 ms   (990.1 ?s .. 2.224 ms)
variance introduced by outliers: 14% (moderately inflated)
@michaelt

This comment has been minimized.

Copy link
Owner Author

michaelt commented Nov 2, 2015

benchmarking map/streaming
time                 15.82 ms   (15.56 ms .. 16.05 ms)
                     0.999 R?   (0.998 R? .. 0.999 R?)
mean                 15.84 ms   (15.59 ms .. 16.04 ms)
std dev              528.2 ?s   (346.4 ?s .. 777.0 ?s)
variance introduced by outliers: 12% (moderately inflated)

benchmarking map/conduit
time                 31.46 ms   (30.65 ms .. 32.78 ms)
                     0.992 R?   (0.976 R? .. 1.000 R?)
mean                 31.22 ms   (30.80 ms .. 32.30 ms)
std dev              1.363 ms   (575.4 ?s .. 2.381 ms)
variance introduced by outliers: 11% (moderately inflated)

benchmarking map/pipes
time                 54.16 ms   (53.03 ms .. 55.82 ms)
                     0.999 R?   (0.997 R? .. 1.000 R?)
mean                 54.53 ms   (54.08 ms .. 55.04 ms)
std dev              872.1 ?s   (667.1 ?s .. 1.149 ms)

benchmarking map/machines
time                 154.0 ms   (144.5 ms .. 164.5 ms)
                     0.997 R?   (0.992 R? .. 1.000 R?)
mean                 160.0 ms   (156.7 ms .. 163.6 ms)
std dev              4.807 ms   (2.763 ms .. 6.922 ms)
variance introduced by outliers: 12% (moderately inflated)

benchmarking drop/streaming
time                 27.32 ms   (26.36 ms .. 28.78 ms)
                     0.992 R?   (0.981 R? .. 0.999 R?)
mean                 26.10 ms   (25.49 ms .. 26.75 ms)
std dev              1.368 ms   (923.2 ?s .. 2.208 ms)
variance introduced by outliers: 16% (moderately inflated)

benchmarking drop/conduit
time                 27.29 ms   (27.07 ms .. 27.51 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 27.64 ms   (27.37 ms .. 28.28 ms)
std dev              835.3 ?s   (300.1 ?s .. 1.604 ms)

benchmarking drop/pipes
time                 28.03 ms   (26.75 ms .. 29.67 ms)
                     0.990 R?   (0.981 R? .. 0.997 R?)
mean                 26.08 ms   (25.41 ms .. 27.01 ms)
std dev              1.781 ms   (1.293 ms .. 2.403 ms)
variance introduced by outliers: 26% (moderately inflated)

benchmarking drop/machines
time                 113.0 ms   (110.5 ms .. 116.2 ms)
                     0.998 R?   (0.993 R? .. 1.000 R?)
mean                 112.1 ms   (110.0 ms .. 114.1 ms)
std dev              3.018 ms   (2.122 ms .. 4.205 ms)
variance introduced by outliers: 11% (moderately inflated)

benchmarking dropWhile/streaming
time                 12.14 ms   (12.00 ms .. 12.29 ms)
                     0.999 R?   (0.998 R? .. 1.000 R?)
mean                 12.02 ms   (11.94 ms .. 12.10 ms)
std dev              213.0 ?s   (167.9 ?s .. 285.3 ?s)

benchmarking dropWhile/conduit
time                 30.31 ms   (29.82 ms .. 31.00 ms)
                     0.999 R?   (0.997 R? .. 1.000 R?)
mean                 30.52 ms   (30.29 ms .. 30.81 ms)
std dev              538.7 ?s   (399.3 ?s .. 705.3 ?s)

benchmarking dropWhile/pipes
time                 26.27 ms   (25.92 ms .. 26.73 ms)
                     0.999 R?   (0.997 R? .. 1.000 R?)
mean                 26.57 ms   (26.29 ms .. 27.00 ms)
std dev              757.5 ?s   (509.2 ?s .. 1.209 ms)

benchmarking dropWhile/machines
time                 79.11 ms   (78.10 ms .. 80.53 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 79.04 ms   (78.37 ms .. 80.09 ms)
std dev              1.309 ms   (734.8 ?s .. 1.951 ms)

benchmarking scan/streaming
time                 17.78 ms   (17.59 ms .. 18.00 ms)
                     0.999 R?   (0.999 R? .. 1.000 R?)
mean                 17.79 ms   (17.68 ms .. 17.94 ms)
std dev              319.7 ?s   (187.0 ?s .. 544.5 ?s)

benchmarking scan/conduit
time                 61.72 ms   (59.90 ms .. 63.88 ms)
                     0.998 R?   (0.997 R? .. 1.000 R?)
mean                 60.78 ms   (60.23 ms .. 61.70 ms)
std dev              1.198 ms   (585.9 ?s .. 1.782 ms)

benchmarking scan/pipes
time                 62.88 ms   (62.15 ms .. 63.79 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 62.24 ms   (61.70 ms .. 62.78 ms)
std dev              947.6 ?s   (713.1 ?s .. 1.414 ms)

benchmarking scan/machines
time                 208.7 ms   (206.5 ms .. 211.8 ms)
                     1.000 R?   (1.000 R? .. 1.000 R?)
mean                 209.6 ms   (208.7 ms .. 210.5 ms)
std dev              1.076 ms   (797.3 ?s .. 1.292 ms)
variance introduced by outliers: 14% (moderately inflated)

benchmarking take/streaming
time                 14.84 ms   (14.62 ms .. 15.04 ms)
                     0.998 R?   (0.995 R? .. 0.999 R?)
mean                 15.01 ms   (14.85 ms .. 15.22 ms)
std dev              457.4 ?s   (300.5 ?s .. 705.2 ?s)
variance introduced by outliers: 11% (moderately inflated)

benchmarking take/conduit
time                 46.16 ms   (45.06 ms .. 47.44 ms)
                     0.999 R?   (0.997 R? .. 1.000 R?)
mean                 45.89 ms   (45.58 ms .. 46.33 ms)
std dev              705.6 ?s   (481.7 ?s .. 1.057 ms)

benchmarking take/pipes
time                 55.05 ms   (53.84 ms .. 56.26 ms)
                     0.999 R?   (0.998 R? .. 1.000 R?)
mean                 54.61 ms   (54.18 ms .. 55.01 ms)
std dev              790.5 ?s   (597.8 ?s .. 1.073 ms)

benchmarking take/machines
time                 210.2 ms   (207.3 ms .. 214.9 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 210.1 ms   (208.7 ms .. 211.4 ms)
std dev              1.633 ms   (1.149 ms .. 2.087 ms)
variance introduced by outliers: 14% (moderately inflated)

benchmarking takeWhile/streaming
time                 15.29 ms   (15.09 ms .. 15.50 ms)
                     0.999 R?   (0.998 R? .. 0.999 R?)
mean                 15.14 ms   (15.00 ms .. 15.26 ms)
std dev              300.2 ?s   (249.7 ?s .. 372.6 ?s)

benchmarking takeWhile/conduit
time                 48.26 ms   (47.56 ms .. 49.16 ms)
                     0.999 R?   (0.998 R? .. 1.000 R?)
mean                 48.54 ms   (48.09 ms .. 49.47 ms)
std dev              1.120 ms   (527.3 ?s .. 1.840 ms)

benchmarking takeWhile/pipes
time                 52.02 ms   (51.24 ms .. 52.51 ms)
                     1.000 R?   (0.999 R? .. 1.000 R?)
mean                 52.97 ms   (52.54 ms .. 53.55 ms)
std dev              914.8 ?s   (652.9 ?s .. 1.277 ms)

benchmarking takeWhile/machines
time                 186.1 ms   (182.1 ms .. 189.1 ms)
                     1.000 R?   (1.000 R? .. 1.000 R?)
mean                 187.4 ms   (186.3 ms .. 188.4 ms)
std dev              1.414 ms   (788.0 ?s .. 1.944 ms)
variance introduced by outliers: 14% (moderately inflated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.