Skip to content

Commit 50a1b4d

Browse files
committed
Benchmarks
1 parent 180c65e commit 50a1b4d

File tree

1 file changed

+12
-1
lines changed
  • containers-tests/benchmarks/Utils

1 file changed

+12
-1
lines changed

containers-tests/benchmarks/Utils/Fold.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ foldBenchmarks foldr foldl foldr' foldl' foldMap xs =
4444

4545
-- foldr'
4646
, bench "foldr'_sum" $ whnf (foldr' (+) 0) xs
47+
, bench "foldr'_maximum" $ whnf foldr'_maximum xs
4748

4849
-- foldl'
4950
, bench "foldl'_sum" $ whnf (foldl' (+) 0) xs
51+
, bench "foldl'_maximum" $ whnf foldl'_maximum xs
5052

5153
-- foldMap
5254
, bench "foldMap_elem" $ whnf foldMap_elem xs
@@ -81,6 +83,12 @@ foldBenchmarks foldr foldl foldr' foldl' foldMap xs =
8183
foldl_traverseSum xs =
8284
execState (foldl (\z x -> modify' (+x) *> z) (pure ()) xs) 0
8385

86+
foldr'_maximum :: f -> Maybe Int
87+
foldr'_maximum = foldr' (\x z -> Just $! maybe x (max x) z) Nothing
88+
89+
foldl'_maximum :: f -> Maybe Int
90+
foldl'_maximum = foldl' (\z x -> Just $! maybe x (max x) z) Nothing
91+
8492
foldMap_elem :: f -> Any
8593
foldMap_elem = foldMap (\x -> Any (x == minBound))
8694

@@ -138,9 +146,12 @@ instance Applicative f => Monoid (Effect f) where
138146
-- Folding with an effect. In practice:
139147
-- * Folds defined using foldr, such as Data.Foldable.traverse_ and friends
140148
--
141-
-- foldl', foldr'
149+
-- foldl'_sum, foldr'_sum
142150
-- Strict folds.
143151
--
152+
-- foldl'_maximum, foldr'_maximum
153+
-- Strict folds with a `Maybe` as accumulator which could be optimized away.
154+
--
144155
-- foldMap_elem
145156
-- Simple lazy fold that visits every element. In practice:
146157
-- * Worst case for lazy folds defined using foldMap, such as

0 commit comments

Comments
 (0)