@@ -20,7 +20,7 @@ import Data.Foldable (asum)
20import Data.Functor (($>))
20import Data.Functor (($>))
21import Data.Maybe (fromMaybe)
21import Data.Maybe (fromMaybe)
22import System.Random (randomRIO)
22import System.Random (randomRIO)
23−import Prelude hiding (any, all, take, sequence, sequenceA, takeWhile)
23+import Prelude hiding (any, all, take, sequence, sequenceA, takeWhile, span)
25import qualified Data.Traversable as TR
25import qualified Data.Traversable as TR
26import qualified Data.Foldable as F
26import qualified Data.Foldable as F
@@ -174,6 +174,37 @@ longestAllAny value =
174 (drainWhile (<= value))
174 (drainWhile (<= value))
177+-------------------------------------------------------------------------------
179+-------------------------------------------------------------------------------
182+span :: MonadThrow m => Int -> SerialT m Int -> m ((), ())
183+span value = IP.parseD (span_ (<= (value `div` 2)) FL.drain FL.drain)
187+ span_ p f1 f2 = PR.splitWith (,) (PR.takeWhile p f1) (PR.fromFold f2)
189+{-# INLINE spanBy #-}
190+spanBy :: MonadThrow m => Int -> SerialT m Int -> m ((), ())
192+ IP.parseD (spanBy_ (\_ i -> i <= (value `div` 2)) FL.drain FL.drain)
196+ spanBy_ c f1 f2 = PR.splitWith (,) (PR.groupBy c f1) (PR.fromFold f2)
198+{-# INLINE spanByRolling #-}
199+spanByRolling :: MonadThrow m => Int -> SerialT m Int -> m ((), ())
200+spanByRolling value =
201+ IP.parseD (spanByRolling_ (\_ i -> i <= value `div` 2) FL.drain FL.drain)
205+ spanByRolling_ c f1 f2 =
206+ PR.splitWith (,) (PR.groupByRolling c f1) (PR.fromFold f2)
177-------------------------------------------------------------------------------
208-------------------------------------------------------------------------------
178-- Parsers in which -fspec-constr-recursive=16 is problematic
209-- Parsers in which -fspec-constr-recursive=16 is problematic
179-------------------------------------------------------------------------------
210-------------------------------------------------------------------------------
@@ -241,6 +272,13 @@ o_1_space_serial value =
241 , benchIOSink value "longest (all,any)" $ longestAllAny value
272 , benchIOSink value "longest (all,any)" $ longestAllAny value
275+o_1_space_serial_derived :: Int -> [Benchmark]
276+o_1_space_serial_derived value =
277+ [ benchIOSink value "span" $ span value
278+ , benchIOSink value "spanBy" $ spanBy value
279+ , benchIOSink value "spanByRolling" $ spanByRolling value
244o_n_heap_serial :: Int -> [Benchmark]
282o_n_heap_serial :: Int -> [Benchmark]
245o_n_heap_serial value =
283o_n_heap_serial value =
@@ -275,6 +313,7 @@ main = do
276 allBenchmarks value =
314 allBenchmarks value =
277 [ bgroup (o_1_space_prefix moduleName) (o_1_space_serial value)
315 [ bgroup (o_1_space_prefix moduleName) (o_1_space_serial value)
316+ , bgroup (o_1_space_prefix moduleName) (o_1_space_serial_derived value)
278 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_serial value)
317 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_serial value)
279 , bgroup (o_n_space_prefix moduleName) (o_n_space_serial value)
318 , bgroup (o_n_space_prefix moduleName) (o_n_space_serial value)