Skip to content

Instantly share code, notes, and snippets.

@wyager

wyager/Concat.hs

Created Jul 12, 2016
Embed
What would you like to do?
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Builder as BB
import qualified Data.Text as TS
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Internal.Builder as TB
import qualified Control.DeepSeq as DS
-- 1.74s
string :: String
string = concat $ replicate (10^7) "Hello world"
-- 1.26s
bs :: BS.ByteString
bs = BS.concat $ replicate (10^7) "Hello world"
-- 0.26s
bl1 :: BL.ByteString
bl1 = BL.concat $ replicate (10^7) "Hello world"
-- 0.23s
bl2 :: BL.ByteString
bl2 = BB.toLazyByteString $ mconcat $ replicate (10^7) $ BB.byteString "Hello world"
-- 1.55s
ts :: TS.Text
ts = TS.concat $ replicate (10^7) "Hello world"
-- 0.27s
tl1 :: TL.Text
tl1 = TL.concat $ replicate (10^7) "Hello world"
-- 1.06s
tl2 :: TL.Text
tl2 = TB.toLazyText $ mconcat $ replicate (10^7) $ TB.fromText "Hello world"
main = print $ DS.deepseq bl2 "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment