From c8aaba38cbd8117aa18355c976d62fb04fd8098c Mon Sep 17 00:00:00 2001 From: Harendra Kumar Date: Wed, 31 Oct 2018 16:50:00 +0530 Subject: [PATCH] Add dropWhileFalse/dropOne Also, disable monadic versions of drop/take. Pure versions use the monadic ones internally so the monadic benchmarks are redundant unless we change the implementations in future. --- benchmark/Linear.hs | 14 +++++++++----- benchmark/LinearOps.hs | 8 ++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/benchmark/Linear.hs b/benchmark/Linear.hs index fac52993f..3cf96192f 100644 --- a/benchmark/Linear.hs +++ b/benchmark/Linear.hs @@ -115,10 +115,12 @@ main = , benchIO "filter-all-in" (Ops.filterAllIn 1) , benchIO "take-all" (Ops.takeAll 1) , benchIO "takeWhile-true" (Ops.takeWhileTrue 1) - , benchIO "takeWhileM-true" (Ops.takeWhileMTrue 1) + --, benchIO "takeWhileM-true" (Ops.takeWhileMTrue 1) + , benchIO "drop-one" (Ops.dropOne 1) , benchIO "drop-all" (Ops.dropAll 1) , benchIO "dropWhile-true" (Ops.dropWhileTrue 1) - , benchIO "dropWhileM-true" (Ops.dropWhileMTrue 1) + --, benchIO "dropWhileM-true" (Ops.dropWhileMTrue 1) + , benchIO "dropWhile-false" (Ops.dropWhileFalse 1) ] , bgroup "filteringN" [ benchIO "filter-even" (Ops.filterEven 4) @@ -126,10 +128,12 @@ main = , benchIO "filter-all-in" (Ops.filterAllIn 4) , benchIO "take-all" (Ops.takeAll 4) , benchIO "takeWhile-true" (Ops.takeWhileTrue 4) - , benchIO "takeWhileM-true" (Ops.takeWhileMTrue 4) + --, benchIO "takeWhileM-true" (Ops.takeWhileMTrue 4) + , benchIO "drop-one" (Ops.dropOne 4) , benchIO "drop-all" (Ops.dropAll 4) , benchIO "dropWhile-true" (Ops.dropWhileTrue 4) - , benchIO "dropWhileM-true" (Ops.dropWhileMTrue 4) + --, benchIO "dropWhileM-true" (Ops.dropWhileMTrue 4) + , benchIO "dropWhile-false" (Ops.dropWhileFalse 4) ] , benchIO "zip" Ops.zip , benchIO "zipM" Ops.zipM @@ -147,7 +151,7 @@ main = ] , bgroup "iterated" [ benchSrcIO serially "mapM" Ops.iterateMapM - , benchSrcIO serially "scan" Ops.iterateScan + , benchSrcIO serially "scan(1/100)" Ops.iterateScan , benchSrcIO serially "filterEven" Ops.iterateFilterEven , benchSrcIO serially "takeAll" Ops.iterateTakeAll , benchSrcIO serially "dropOne" Ops.iterateDropOne diff --git a/benchmark/LinearOps.hs b/benchmark/LinearOps.hs index b5fe97b92..9a2f6891e 100644 --- a/benchmark/LinearOps.hs +++ b/benchmark/LinearOps.hs @@ -242,14 +242,16 @@ composeN' n f = {-# INLINE takeAll #-} {-# INLINE takeWhileTrue #-} {-# INLINE takeWhileMTrue #-} +{-# INLINE dropOne #-} {-# INLINE dropAll #-} {-# INLINE dropWhileTrue #-} {-# INLINE dropWhileMTrue #-} +{-# INLINE dropWhileFalse #-} {-# INLINE findIndices #-} {-# INLINE elemIndices #-} scan, map, fmap, mapMaybe, filterEven, filterAllOut, - filterAllIn, takeOne, takeAll, takeWhileTrue, takeWhileMTrue, dropAll, - dropWhileTrue, dropWhileMTrue, + filterAllIn, takeOne, takeAll, takeWhileTrue, takeWhileMTrue, dropOne, + dropAll, dropWhileTrue, dropWhileMTrue, dropWhileFalse, findIndices, elemIndices :: Monad m => Int -> Stream m Int -> m () @@ -281,9 +283,11 @@ takeOne n = composeN n $ S.take 1 takeAll n = composeN n $ S.take maxValue takeWhileTrue n = composeN n $ S.takeWhile (<= maxValue) takeWhileMTrue n = composeN n $ S.takeWhileM (return . (<= maxValue)) +dropOne n = composeN n $ S.drop 1 dropAll n = composeN n $ S.drop maxValue dropWhileTrue n = composeN n $ S.dropWhile (<= maxValue) dropWhileMTrue n = composeN n $ S.dropWhileM (return . (<= maxValue)) +dropWhileFalse n = composeN n $ S.dropWhile (<= 1) findIndices n = composeN n $ S.findIndices (== maxValue) elemIndices n = composeN n $ S.elemIndices maxValue