on master help sign in
Add foldl' benchmark for pure streams to cmp with Foldable
commit6daacf0d490697d39fbe97d375380b603280a49e authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 19 Nov 2018, 12:44 (8 years ago) parent11d8d6d
2 files changed+9−4
benchmark/Linear.hs+4−3 benchmark/LinearOps.hs+5−1
benchmark/Linear.hs+4−3
@@ -75,9 +75,10 @@ main =
7575 , benchPureSink "showsPrec" Ops.showInstance
7676 , benchPure "showsPrecList" (\n -> S.fromList [1..n :: Int])
7777 Ops.showInstanceList
78− , benchPureSink "foldable-foldl'" Ops.foldableFoldl'
79− , benchPureSink "foldable-sum" Ops.foldableSum
80− , benchPureSinkIO "traversable-mapM" Ops.traversableMapM
78+ , benchPureSink "foldl'" Ops.pureFoldl'
79+ , benchPureSink "foldable/foldl'" Ops.foldableFoldl'
80+ , benchPureSink "foldable/sum" Ops.foldableSum
81+ , benchPureSinkIO "traversable/mapM" Ops.traversableMapM
8182 ]
8283 , bgroup "generation"
8384 [ -- Most basic, barely stream continuations running
benchmark/LinearOps.hs+5−1
@@ -12,7 +12,7 @@
1212module LinearOps where
1313
1414import Control.Monad (when)
15−import Data.Functor.Identity (Identity)
15+import Data.Functor.Identity (Identity, runIdentity)
1616import Data.Maybe (fromJust)
1717import Prelude
1818 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=), (==), (<=),
@@ -453,6 +453,10 @@ readInstance src =
453453 [(x,"")] -> src S.<> x
454454 _ -> P.error "readInstance: no parse"
455455
456+{-# INLINE pureFoldl' #-}
457+pureFoldl' :: Stream Identity Int -> Int
458+pureFoldl' = runIdentity . S.foldl' (+) 0
459+
456460{-# INLINE foldableFoldl' #-}
457461foldableFoldl' :: Stream Identity Int -> Int
458462foldableFoldl' = F.foldl' (+) 0