mirror of
https://github.com/composewell/streamly.git
synced 2024-11-10 12:47:22 +03:00
ef958917ee
It improves many benchmarks significantly.
69 lines
2.1 KiB
Haskell
69 lines
2.1 KiB
Haskell
-- |
|
|
-- Module : Main
|
|
-- Copyright : (c) 2018 Harendra Kumar
|
|
--
|
|
-- License : BSD3
|
|
-- Maintainer : streamly@composewell.com
|
|
|
|
-- Rate benchmarks are kept separate because they need more running time to
|
|
-- provide stable results.
|
|
|
|
-- import Data.Functor.Identity (Identity, runIdentity)
|
|
import System.Random (randomRIO)
|
|
|
|
import Common (parseCLIOpts)
|
|
|
|
import Streamly
|
|
import Gauge
|
|
|
|
import qualified Streamly.Benchmark.Prelude as Ops
|
|
|
|
-- | Takes a source, and uses it with a default drain/fold method.
|
|
{-# INLINE benchSrcIO #-}
|
|
benchSrcIO
|
|
:: (t IO Int -> SerialT IO Int)
|
|
-> String
|
|
-> (Int -> t IO Int)
|
|
-> Benchmark
|
|
benchSrcIO t name f
|
|
= bench name $ nfIO $ randomRIO (1,1) >>= Ops.toNull t . f
|
|
|
|
{-
|
|
_benchId :: NFData b => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
|
|
_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
|
|
-}
|
|
|
|
defaultStreamSize :: Int
|
|
defaultStreamSize = 100000
|
|
|
|
main :: IO ()
|
|
main = do
|
|
-- XXX Fix indentation
|
|
(value, cfg, benches) <- parseCLIOpts defaultStreamSize
|
|
value `seq` runMode (mode cfg) cfg benches
|
|
-- XXX arbitrarily large rate should be the same as rate Nothing
|
|
[ bgroup "avgrate"
|
|
[ bgroup "asyncly"
|
|
[ -- benchIO "unfoldr" $ Ops.toNull asyncly
|
|
benchSrcIO asyncly "unfoldrM" (Ops.sourceUnfoldrM value)
|
|
, benchSrcIO asyncly "unfoldrM/Nothing"
|
|
(rate Nothing . Ops.sourceUnfoldrM value)
|
|
, benchSrcIO asyncly "unfoldrM/1,000,000"
|
|
(avgRate 1000000 . Ops.sourceUnfoldrM value)
|
|
, benchSrcIO asyncly "unfoldrM/3,000,000"
|
|
(avgRate 3000000 . Ops.sourceUnfoldrM value)
|
|
, benchSrcIO asyncly "unfoldrM/10,000,000/maxThreads1"
|
|
(maxThreads 1 . avgRate 10000000 . Ops.sourceUnfoldrM value)
|
|
, benchSrcIO asyncly "unfoldrM/10,000,000"
|
|
(avgRate 10000000 . Ops.sourceUnfoldrM value)
|
|
, benchSrcIO asyncly "unfoldrM/20,000,000"
|
|
(avgRate 20000000 . Ops.sourceUnfoldrM value)
|
|
]
|
|
, bgroup "aheadly"
|
|
[
|
|
benchSrcIO aheadly "unfoldrM/1,000,000"
|
|
(avgRate 1000000 . Ops.sourceUnfoldrM value)
|
|
]
|
|
]
|
|
]
|