mirror of
https://github.com/composewell/streamly.git
synced 2024-09-20 16:08:20 +03:00
merge nested and nested-unfold benchmarks with others
merge them with other serial stream benchmarks.
This commit is contained in:
parent
0b00efe4f6
commit
7ce2dc87ea
@ -1,61 +0,0 @@
|
||||
-- |
|
||||
-- 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 Streamly.Benchmark.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
|
||||
-- XXX takes too much stack space
|
||||
, 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
|
||||
]
|
||||
]
|
@ -1,38 +0,0 @@
|
||||
-- |
|
||||
-- Module : NestedUnfold
|
||||
-- Copyright : (c) 2019 Composewell Technologies
|
||||
--
|
||||
-- License : BSD3
|
||||
-- Maintainer : streamly@composewell.com
|
||||
|
||||
import Control.DeepSeq (NFData)
|
||||
import System.Random (randomRIO)
|
||||
|
||||
import Streamly.Benchmark.Common (parseCLIOpts)
|
||||
|
||||
import qualified NestedUnfoldOps as Ops
|
||||
|
||||
import Gauge
|
||||
|
||||
benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
|
||||
benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
|
||||
|
||||
defaultStreamSize :: Int
|
||||
defaultStreamSize = 100000
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
(linearCount, cfg, benches) <- parseCLIOpts defaultStreamSize
|
||||
linearCount `seq` runMode (mode cfg) cfg benches
|
||||
[ bgroup "unfold"
|
||||
[ benchIO "toNull" $ Ops.toNull linearCount
|
||||
, benchIO "toNull3" $ Ops.toNull3 linearCount
|
||||
, benchIO "concat" $ Ops.concat linearCount
|
||||
-- , benchIO "toList" $ Ops.toList
|
||||
, benchIO "toListSome" $ Ops.toListSome linearCount
|
||||
, benchIO "filterAllOut" $ Ops.filterAllOut linearCount
|
||||
, benchIO "filterAllIn" $ Ops.filterAllIn linearCount
|
||||
, benchIO "filterSome" $ Ops.filterSome linearCount
|
||||
, benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount
|
||||
]
|
||||
]
|
@ -24,6 +24,9 @@ import qualified Streamly.Internal.Data.Fold as IFL
|
||||
import qualified Streamly.Internal.Prelude as IP
|
||||
import qualified Streamly.Internal.Data.Pipe as Pipe
|
||||
|
||||
import qualified NestedOps as Nested
|
||||
import qualified NestedUnfoldOps as NestedUnfold
|
||||
|
||||
import Gauge
|
||||
import Streamly.Benchmark.Common
|
||||
|
||||
@ -70,6 +73,9 @@ benchIOSrc t name f =
|
||||
benchPureSink :: NFData b => Int -> String -> (SerialT Identity Int -> b) -> Benchmark
|
||||
benchPureSink value name f = benchPure name (Ops.sourceUnfoldr value) f
|
||||
|
||||
benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
|
||||
benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
--
|
||||
-------------------------------------------------------------------------------
|
||||
@ -392,43 +398,76 @@ main = do
|
||||
, benchIOSrc1 "concatMapWithAppend (2,x/2)"
|
||||
(Ops.concatMapWithAppend 2 (value `div` 2))
|
||||
]
|
||||
, bgroup "concat-interleave"
|
||||
, bgroup "outer-product-streams"
|
||||
[ benchIO "toNullAp" $ Nested.toNullAp value serially
|
||||
, benchIO "toNull" $ Nested.toNull value serially
|
||||
, benchIO "toNull3" $ Nested.toNull3 value serially
|
||||
, benchIO "filterAllOut" $ Nested.filterAllOut value serially
|
||||
, benchIO "filterAllIn" $ Nested.filterAllIn value serially
|
||||
, benchIO "filterSome" $ Nested.filterSome value serially
|
||||
, benchIO "breakAfterSome" $ Nested.breakAfterSome value serially
|
||||
]
|
||||
, bgroup "outer-product-unfolds"
|
||||
[ benchIO "toNull" $ NestedUnfold.toNull value
|
||||
, benchIO "toNull3" $ NestedUnfold.toNull3 value
|
||||
, benchIO "concat" $ NestedUnfold.concat value
|
||||
, benchIO "filterAllOut" $ NestedUnfold.filterAllOut value
|
||||
, benchIO "filterAllIn" $ NestedUnfold.filterAllIn value
|
||||
, benchIO "filterSome" $ NestedUnfold.filterSome value
|
||||
, benchIO "breakAfterSome" $ NestedUnfold.breakAfterSome value
|
||||
]
|
||||
-- scanl-map and foldl-map are equivalent to the scan and fold in the foldl
|
||||
-- library. If scan/fold followed by a map is efficient enough we may not
|
||||
-- need monolithic implementations of these.
|
||||
, bgroup "mixed"
|
||||
[ benchIOSink value "scanl-map" (Ops.scanMap 1)
|
||||
, benchIOSink value "foldl-map" Ops.foldl'ReduceMap
|
||||
, benchIOSink value "sum-product-fold" Ops.sumProductFold
|
||||
, benchIOSink value "sum-product-scan" Ops.sumProductScan
|
||||
]
|
||||
, bgroup "mixedX4"
|
||||
[ benchIOSink value "scan-map" (Ops.scanMap 4)
|
||||
, benchIOSink value "drop-map" (Ops.dropMap 4)
|
||||
, benchIOSink value "drop-scan" (Ops.dropScan 4)
|
||||
, benchIOSink value "take-drop" (Ops.takeDrop value 4)
|
||||
, benchIOSink value "take-scan" (Ops.takeScan value 4)
|
||||
, benchIOSink value "take-map" (Ops.takeMap value 4)
|
||||
, benchIOSink value "filter-drop" (Ops.filterDrop value 4)
|
||||
, benchIOSink value "filter-take" (Ops.filterTake value 4)
|
||||
, benchIOSink value "filter-scan" (Ops.filterScan 4)
|
||||
, benchIOSink value "filter-scanl1" (Ops.filterScanl1 4)
|
||||
, benchIOSink value "filter-map" (Ops.filterMap value 4)
|
||||
]
|
||||
]
|
||||
, bgroup "wSerially"
|
||||
[ bgroup "transformation"
|
||||
[ benchIOSink value "fmap" $ Ops.fmap' wSerially 1
|
||||
]
|
||||
, bgroup "concatMap"
|
||||
[ benchIOSrc1 "concatMapWithWSerial (2,x/2)"
|
||||
(Ops.concatMapWithWSerial 2 (value `div` 2))
|
||||
, benchIOSrc1 "concatMapWithWSerial (x/2,2)"
|
||||
(Ops.concatMapWithWSerial (value `div` 2) 2)
|
||||
]
|
||||
-- scanl-map and foldl-map are equivalent to the scan and fold in the foldl
|
||||
-- library. If scan/fold followed by a map is efficient enough we may not
|
||||
-- need monolithic implementations of these.
|
||||
, bgroup "mixed"
|
||||
[ benchIOSink value "scanl-map" (Ops.scanMap 1)
|
||||
, benchIOSink value "foldl-map" Ops.foldl'ReduceMap
|
||||
, benchIOSink value "sum-product-fold" Ops.sumProductFold
|
||||
, benchIOSink value "sum-product-scan" Ops.sumProductScan
|
||||
]
|
||||
, bgroup "mixedX4"
|
||||
[ benchIOSink value "scan-map" (Ops.scanMap 4)
|
||||
, benchIOSink value "drop-map" (Ops.dropMap 4)
|
||||
, benchIOSink value "drop-scan" (Ops.dropScan 4)
|
||||
, benchIOSink value "take-drop" (Ops.takeDrop value 4)
|
||||
, benchIOSink value "take-scan" (Ops.takeScan value 4)
|
||||
, benchIOSink value "take-map" (Ops.takeMap value 4)
|
||||
, benchIOSink value "filter-drop" (Ops.filterDrop value 4)
|
||||
, benchIOSink value "filter-take" (Ops.filterTake value 4)
|
||||
, benchIOSink value "filter-scan" (Ops.filterScan 4)
|
||||
, benchIOSink value "filter-scanl1" (Ops.filterScanl1 4)
|
||||
, benchIOSink value "filter-map" (Ops.filterMap value 4)
|
||||
]
|
||||
]
|
||||
, bgroup "wSerially"
|
||||
[ bgroup "transformation"
|
||||
[ benchIOSink value "fmap" $ Ops.fmap' wSerially 1
|
||||
]
|
||||
, bgroup "outer-product"
|
||||
[ benchIO "toNullAp" $ Nested.toNullAp value wSerially
|
||||
, benchIO "toNull" $ Nested.toNull value wSerially
|
||||
, benchIO "toNull3" $ Nested.toNull3 value wSerially
|
||||
, benchIO "filterAllOut" $ Nested.filterAllOut value wSerially
|
||||
, benchIO "filterAllIn" $ Nested.filterAllIn value wSerially
|
||||
, benchIO "filterSome" $ Nested.filterSome value wSerially
|
||||
, benchIO "breakAfterSome" $ Nested.breakAfterSome value wSerially
|
||||
]
|
||||
]
|
||||
, bgroup "zipSerially"
|
||||
[ bgroup "transformation"
|
||||
[ benchIOSink value "fmap" $ Ops.fmap' zipSerially 1
|
||||
]
|
||||
[ bgroup "transformation"
|
||||
[ benchIOSink value "fmap" $ Ops.fmap' zipSerially 1
|
||||
]
|
||||
-- XXX needs fixing
|
||||
{-
|
||||
, bgroup "outer-product"
|
||||
[ benchIO "toNullAp" $ Nested.toNullAp value zipSerially
|
||||
]
|
||||
-}
|
||||
]
|
||||
]
|
||||
|
@ -11,6 +11,9 @@ import System.Random (randomRIO)
|
||||
|
||||
import qualified Streamly.Benchmark.Prelude as Ops
|
||||
|
||||
import qualified NestedOps as Nested
|
||||
import qualified NestedUnfoldOps as NestedUnfold
|
||||
|
||||
import Streamly
|
||||
import Gauge
|
||||
import Streamly.Benchmark.Common
|
||||
@ -49,6 +52,9 @@ benchPureSinkIO
|
||||
benchPureSinkIO value name f =
|
||||
bench name $ nfIO $ randomRIO (1, 1) >>= f . Ops.sourceUnfoldr value
|
||||
|
||||
benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
|
||||
benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Benchmarks
|
||||
-------------------------------------------------------------------------------
|
||||
@ -72,6 +78,18 @@ main = do
|
||||
-- , benchIOSink size "toPure" Ops.toPure
|
||||
-- , benchIOSink size "toPureRev" Ops.toPureRev
|
||||
]
|
||||
, bgroup "outer-product-streams"
|
||||
[ benchIO "toList" $ Nested.toList size serially
|
||||
, benchIO "toListSome" $ Nested.toListSome size serially
|
||||
]
|
||||
, bgroup "outer-product-unfolds"
|
||||
[ benchIO "toList" $ NestedUnfold.toList size
|
||||
, benchIO "toListSome" $ NestedUnfold.toListSome size
|
||||
]
|
||||
, bgroup "outer-product-wserial"
|
||||
[ benchIO "toList" $ Nested.toList size wSerially
|
||||
, benchIO "toListSome" $ Nested.toListSome size wSerially
|
||||
]
|
||||
-- Buffering operations using heap proportional to number of elements.
|
||||
, bgroup "traversable" -- < 2MB
|
||||
[ -- Traversable instance
|
||||
|
@ -166,6 +166,7 @@ benchmark linear
|
||||
type: exitcode-stdio-1.0
|
||||
ghc-options: -with-rtsopts "-T -K36K -M16M"
|
||||
main-is: Streamly/Benchmark/Prelude/Serial/O_1_Space.hs
|
||||
other-modules: NestedOps, NestedUnfoldOps
|
||||
|
||||
benchmark serial-O-n-heap
|
||||
import: bench-options
|
||||
@ -184,20 +185,7 @@ benchmark serial-O-n-space
|
||||
type: exitcode-stdio-1.0
|
||||
ghc-options: -with-rtsopts "-T -K16M -M64M"
|
||||
main-is: Streamly/Benchmark/Prelude/Serial/O_n_Space.hs
|
||||
|
||||
benchmark nested
|
||||
import: bench-options
|
||||
type: exitcode-stdio-1.0
|
||||
ghc-options: -with-rtsopts "-T -K256K -M16M"
|
||||
main-is: Nested.hs
|
||||
other-modules: NestedOps
|
||||
|
||||
benchmark nested-unfold
|
||||
import: bench-options
|
||||
type: exitcode-stdio-1.0
|
||||
ghc-options: -with-rtsopts "-T -K64K -M16M"
|
||||
main-is: NestedUnfold.hs
|
||||
other-modules: NestedUnfoldOps
|
||||
other-modules: NestedOps, NestedUnfoldOps
|
||||
|
||||
benchmark base
|
||||
import: bench-options
|
||||
|
Loading…
Reference in New Issue
Block a user