streamly/benchmark/Nested.hs
Harendra Kumar afc02e6970 separate const mem benchmarks from buffered ones
Streaming benchmarks take constant memory whereas the buffering ones take
memory proportional to the stream size. We would like to test them separately.
For streaming benchmarks we can use a very large stream size to make sure there
is no space leak and we are running in constant memory for long time.
2020-01-16 18:50:30 +05:30

61 lines
2.3 KiB
Haskell

-- |
-- Module : Main
-- Copyright : (c) 2018 Harendra Kumar
--
-- License : BSD3
-- Maintainer : streamly@composewell.com
import Control.DeepSeq (NFData)
import Data.Functor.Identity (Identity, runIdentity)
import System.Random (randomRIO)
import Common (parseCLIOpts)
import Streamly
import Gauge
import qualified NestedOps as Ops
benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
_benchId :: (NFData b) => String -> (Int -> Identity b) -> Benchmark
_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
defaultStreamSize :: Int
defaultStreamSize = 100000
main :: IO ()
main = do
-- XXX Fix indentation
(linearCount, cfg, benches) <- parseCLIOpts defaultStreamSize
linearCount `seq` runMode (mode cfg) cfg benches
[ bgroup "serially"
[ benchIO "toNullAp" $ Ops.toNullAp linearCount serially
, benchIO "toNull" $ Ops.toNull linearCount serially
, benchIO "toNull3" $ Ops.toNull3 linearCount serially
-- , benchIO "toList" $ Ops.toList linearCount serially
, benchIO "toListSome" $ Ops.toListSome linearCount serially
, benchIO "filterAllOut" $ Ops.filterAllOut linearCount serially
, benchIO "filterAllIn" $ Ops.filterAllIn linearCount serially
, benchIO "filterSome" $ Ops.filterSome linearCount serially
, benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount serially
]
, bgroup "wSerially"
[ benchIO "toNullAp" $ Ops.toNullAp linearCount wSerially
, benchIO "toNull" $ Ops.toNull linearCount wSerially
, benchIO "toNull3" $ Ops.toNull3 linearCount wSerially
-- , benchIO "toList" $ Ops.toList linearCount wSerially
, benchIO "toListSome" $ Ops.toListSome linearCount wSerially
, benchIO "filterAllOut" $ Ops.filterAllOut linearCount wSerially
, benchIO "filterAllIn" $ Ops.filterAllIn linearCount wSerially
, benchIO "filterSome" $ Ops.filterSome linearCount wSerially
, benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount wSerially
]
, bgroup "zipSerially"
[ benchIO "toNullAp" $ Ops.toNullAp linearCount zipSerially
]
]