@@ -0,0 +1,177 @@
1+{-# LANGUAGE MagicHash #-}
3+import qualified Data.ByteString.Char8 as B8
4+import Control.Exception (evaluate)
5+import Control.DeepSeq (NFData(..))
8+import qualified Codec.Binary.UTF8.Generic as UTF8
9+import qualified Data.Text as T
10+import qualified Data.List as L
11+import Data.Text.Encoding
12+import qualified Criterion.MultiMap as M
13+import Criterion.Config
18+ | False = defaultConfig {
19+ -- Always display an 800x600 window.
20+ cfgPlot = M.singleton KernelDensity (Window 800 600)
22+ | otherwise = defaultConfig
24+instance NFData B8.ByteString
27+ s0 <- B8.readFile "text/test/russian.txt"
28+ let !s0l = B8.length s0
31+ l0 = UTF8.toString s0
33+ s1 = B8.map toUpper s0
37+ l1 = L.map toUpper l0
42+ evaluate (rnf (sl,tl,ll))
43+ defaultMainWith myConfig [
45+ bench "text" $ nf (T.append t1) t0
46+ , bench "b8" $ nf (B8.append s1) s0
47+ , bench "list" $ nf ((++) l1) l0
50+ bench "text" $ nf T.concat tl
51+ , bench "b8" $ nf B8.concat sl
52+ , bench "list" $ nf L.concat ll
55+ bench "text" $ nf decodeUtf8 s0
56+ , bench "b8" $ nf B8.unpack s0
57+ , bench "utf8-string" $ nf UTF8.toString s0
60+ bench "text" $ nf (T.drop (t0l `div` 3)) t0
61+ , bench "b8" $ nf (B8.drop (s0l `div` 3)) s0
62+ , bench "list" $ nf (L.drop (l0l `div` 3)) l0
65+ bench "text" $ nf (T.filter p0) t0
66+ , bench "b8" $ nf (B8.filter p0) s0
67+ , bench "list" $ nf (L.filter p0) l0
70+ bench "text" $ nf (T.filter p1 . T.filter p0) t0
71+ , bench "b8" $ nf (B8.filter p1 . B8.filter p0) s0
72+ , bench "list" $ nf (L.filter p1 . L.filter p0) l0
75+ bench "text" $ nf (T.foldl' len 0) t0
76+ , bench "b8" $ nf (B8.foldl' len 0) s0
77+ , bench "list" $ nf (L.foldl' len 0) l0
80+ bench "text" $ nf (L.length . T.foldr (:) []) t0
81+ , bench "b8" $ nf (L.length . B8.foldr (:) []) s0
82+ , bench "list" $ nf (L.length . L.foldr (:) []) l0
85+ bench "text" $ nf (T.isInfixOf (T.pack w)) t0
86+ , bench "b8" $ nf (B8.isInfixOf (B8.pack w)) s0
87+ , bench "list" $ nf (L.isInfixOf w) l0
90+ bench "text" $ nf T.last t0
91+ , bench "b8" $ nf B8.last s0
92+ , bench "list" $ nf L.last l0
95+ bench "text" $ nf (T.map f) t0
96+ , bench "b8" $ nf (B8.map f) s0
97+ , bench "list" $ nf (L.map f) l0
100+ bench "text" $ nf (T.map f . T.map f) t0
101+ , bench "b8" $ nf (B8.map f . B8.map f) s0
102+ , bench "list" $ nf (L.map f . L.map f) l0
105+ bench "text" $ nf T.reverse t0
106+ , bench "b8" $ nf B8.reverse s0
107+ , bench "list" $ nf L.reverse l0
110+ bench "text" $ nf (T.take (t0l `div` 3)) t0
111+ , bench "b8" $ nf (B8.take (s0l `div` 3)) s0
112+ , bench "list" $ nf (L.take (l0l `div` 3)) l0
115+ bench "text" $ nf T.words t0
116+ , bench "b8" $ nf B8.words s0
117+ , bench "list" $ nf L.words l0
120+ bench "text" $ nf (T.zipWith min t1) t0
121+ , bench "b8" $ nf (B8.zipWith min s1) s0
122+ , bench "list" $ nf (L.zipWith min l1) l0
126+ bench "text" $ nf (T.length . decodeUtf8) s0
127+ , bench "b8" $ nf (L.length . B8.unpack) s0
128+ , bench "utf8-string" $ nf (L.length . UTF8.toString) s0
131+ bench "text" $ nf (T.length . T.drop (t0l `div` 3)) t0
132+ , bench "b8" $ nf (B8.length . B8.drop (s0l `div` 3)) s0
133+ , bench "list" $ nf (L.length . L.drop (l0l `div` 3)) l0
136+ bench "text" $ nf (T.length . T.filter p0) t0
137+ , bench "b8" $ nf (B8.length . B8.filter p0) s0
138+ , bench "list" $ nf (L.length . L.filter p0) l0
141+ bench "text" $ nf (T.length . T.filter p1 . T.filter p0) t0
142+ , bench "b8" $ nf (B8.length . B8.filter p1 . B8.filter p0) s0
143+ , bench "list" $ nf (L.length . L.filter p1 . L.filter p0) l0
146+ bench "text" $ nf (T.length . T.map f) t0
147+ , bench "b8" $ nf (B8.length . B8.map f) s0
148+ , bench "list" $ nf (L.length . L.map f) l0
151+ bench "text" $ nf (T.length . T.map f . T.map f) t0
152+ , bench "b8" $ nf (B8.length . B8.map f . B8.map f) s0
153+ , bench "list" $ nf (L.length . L.map f . L.map f) l0
156+ bench "text" $ nf (T.length . T.take (t0l `div` 3)) t0
157+ , bench "b8" $ nf (B8.length . B8.take (s0l `div` 3)) s0
158+ , bench "list" $ nf (L.length . L.take (l0l `div` 3)) l0
161+ bench "text" $ nf (L.length . T.words) t0
162+ , bench "b8" $ nf (L.length . B8.words) s0
163+ , bench "list" $ nf (L.length . L.words) l0
166+ bench "text" $ nf (T.length . T.zipWith min t1) t0
167+ , bench "b8" $ nf (L.length . B8.zipWith min s1) s0
168+ , bench "list" $ nf (L.length . L.zipWith min l1) l0
176+ f (C# c#) = C# (chr# (ord# c# +# 1#))
177+ len l _ = l + (1::Int)