on master help sign in
Benchmark concatMap, and redefine it to not use fusion.
b3fad05Bryan O'Sullivan
Data/Text.hs+2−5
@@ -574,12 +574,9 @@ concat ts = Text (A.run go) 0 len
574{-# INLINE concat #-}
574{-# INLINE concat #-}
575
575
576-- | /O(n)/ Map a function over a 'Text' that results in a 'Text', and
576-- | /O(n)/ Map a function over a 'Text' that results in a 'Text', and
577−-- concatenate the results. Subject to fusion.
577+-- concatenate the results.
578−--
579−-- Note: if in 'concatMap' @f@ @t@, @f@ is defined in terms of fusible
580−-- functions, it will also be fusible.
581concatMap :: (Char -> Text) -> Text -> Text
578concatMap :: (Char -> Text) -> Text -> Text
582−concatMap f t = unstream (S.concatMap (stream . f) (stream t))
579+concatMap f = concat . foldr ((:) . f) []
583{-# INLINE concatMap #-}
580{-# INLINE concatMap #-}
584
581
585-- | /O(n)/ 'any' @p@ @t@ determines whether any character in the
582-- | /O(n)/ 'any' @p@ @t@ determines whether any character in the
tests/Benchmarks.hs+5
@@ -51,6 +51,11 @@ main = do
51 , bench "b8" $ nf B8.concat sl
51 , bench "b8" $ nf B8.concat sl
52 , bench "list" $ nf L.concat ll
52 , bench "list" $ nf L.concat ll
53 ],
53 ],
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+ ],
54 bgroup "decode" [
59 bgroup "decode" [
55 bench "text" $ nf decodeUtf8 s0
60 bench "text" $ nf decodeUtf8 s0
56 , bench "b8" $ nf B8.unpack s0
61 , bench "b8" $ nf B8.unpack s0