on master help sign in
Benchmark concatMap, and redefine it to not use fusion.

--HG-- extra : convert_revision : 1c709715ad97113e06e77d2c441b8b3b5adf4cf8

commitb3fad059bdc33f2fc09b4921db2005ad8ba85288 authorBryan O'Sullivan <bos@serpentine.com> dateMon 30 Nov 2009, 07:10 (17 years ago) parent2ebdd17
2 files changed+7−5
Data/Text.hs+2−5 tests/Benchmarks.hs+5
Data/Text.hs+2−5
@@ -574,12 +574,9 @@ concat ts = Text (A.run go) 0 len
574574{-# INLINE concat #-}
575575
576576-- | /O(n)/ Map a function over a 'Text' that results in a 'Text', and
577−-- concatenate the results. Subject to fusion.
578−--
579−-- Note: if in 'concatMap' @f@ @t@, @f@ is defined in terms of fusible
580−-- functions, it will also be fusible.
577+-- concatenate the results.
581578concatMap :: (Char -> Text) -> Text -> Text
582−concatMap f t = unstream (S.concatMap (stream . f) (stream t))
579+concatMap f = concat . foldr ((:) . f) []
583580{-# INLINE concatMap #-}
584581
585582-- | /O(n)/ 'any' @p@ @t@ determines whether any character in the
tests/Benchmarks.hs+5
@@ -51,6 +51,11 @@ main = do
5151 , bench "b8" $ nf B8.concat sl
5252 , bench "list" $ nf L.concat ll
5353 ],
54+ bgroup "concatMap" [
55+ bench "text" $ nf (T.concatMap (T.replicate 3 . T.singleton)) t0
56+ , bench "b8" $ nf (B8.concatMap (B8.replicate 3)) s0
57+ , bench "list" $ nf (L.concatMap (L.replicate 3 . (:[]))) l0
58+ ],
5459 bgroup "decode" [
5560 bench "text" $ nf decodeUtf8 s0
5661 , bench "b8" $ nf B8.unpack s0