on master help sign in
Equality benchmark: force eq for lazy BS contents
commitdf43212b0c45a150dba3aa89e4b0a109899f6659 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateWed 1 Jun 2011, 17:00 (15 years ago) parentaf4209c
1 file changed+9−4
tests/benchmarks/src/Data/Text/Benchmarks/Equality.hs+9−4
tests/benchmarks/src/Data/Text/Benchmarks/Equality.hs+9−4
@@ -6,7 +6,7 @@ module Data.Text.Benchmarks.Equality
66 benchmark
77 ) where
88
9−import Criterion (Benchmark, bgroup, bench, whnf)
9+import Criterion (Benchmark, bgroup, bench, whnf, nf)
1010import qualified Data.ByteString.Char8 as B
1111import qualified Data.ByteString.Lazy.Char8 as BL
1212import qualified Data.Text as T
@@ -17,14 +17,19 @@ import qualified Data.Text.Lazy.Encoding as TL
1717benchmark :: FilePath -> IO Benchmark
1818benchmark fp = do
1919 b <- B.readFile fp
20− bl <- BL.readFile fp
20+ bl1 <- BL.readFile fp
21+ -- A lazy bytestring is a list of chunks. When we do not explicitly create two
22+ -- different lazy bytestrings at a different address, the bytestring library
23+ -- will compare the chunk addresses instead of the chunk contents. This is why
24+ -- we read the lazy bytestring twice here.
25+ bl2 <- BL.readFile fp
2126 l <- readFile fp
2227 let t = T.decodeUtf8 b
23− tl = TL.decodeUtf8 bl
28+ tl = TL.decodeUtf8 bl1
2429 return $ bgroup "Equality"
2530 [ bench "Text" $ whnf (== T.init t `T.snoc` '\xfffd') t
2631 , bench "LazyText" $ whnf (== TL.init tl `TL.snoc` '\xfffd') tl
2732 , bench "ByteString" $ whnf (== B.init b `B.snoc` '\xfffd') b
28− , bench "LazyByteString" $ whnf (== BL.init bl `BL.snoc` '\xfffd') bl
33+ , bench "LazyByteString" $ nf (== BL.init bl2 `BL.snoc` '\xfffd') bl1
2934 , bench "String" $ whnf (== init l ++ "\xfffd") l
3035 ]