on master help sign in
Simplify the equality benchmark
3c31b27Bryan O'Sullivan
tests/benchmarks/Equality.hs+12−12
@@ -6,21 +6,21 @@ import qualified Data.Text.Encoding as T
6import qualified Data.Text.Lazy as TL
6import qualified Data.Text.Lazy as TL
7import qualified Data.Text.Lazy.Encoding as TL
7import qualified Data.Text.Lazy.Encoding as TL
8
8
9−text needle haystack = do
9+text haystack = do
10− bs <- B.readFile haystack
10+ ls <- (T.lines . T.decodeUtf8) `fmap` B.readFile haystack
11− print . length . filter (==needle) . T.lines . T.decodeUtf8 $ bs
11+ print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
12
12
13−lazyText needle haystack = do
13+lazyText haystack = do
14− bs <- BL.readFile haystack
14+ ls <- (TL.lines . TL.decodeUtf8) `fmap` BL.readFile haystack
15− print . length . filter (==needle) . TL.lines . TL.decodeUtf8 $ bs
15+ print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
16
16
17−string needle haystack = do
17+string haystack = do
18− s <- readFile haystack
18+ ls <- lines `fmap` readFile haystack
19− print . length . filter (==needle) . lines $ s
19+ print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
20
20
21main = do
21main = do
22 args <- getArgs
22 args <- getArgs
23 case args of
23 case args of
24− ["text",n,h] -> text (T.pack n) h
24+ ["text",h] -> text h
25− ["lazytext",n,h] -> lazyText (TL.pack n) h
25+ ["lazytext",h] -> lazyText h
26− ["string",n,h] -> string n h
26+ ["string",h] -> string h