on master help sign in
Simplify the equality benchmark

--HG-- extra : convert_revision : f3d921643e2f9437add35f7ff6ae27b7097e70d9

commit3c31b271fb2627de54cd5d9eb0758a4baf49dd0d authorBryan O'Sullivan <bos@serpentine.com> dateTue 19 Oct 2010, 04:30 (16 years ago) parent21a4f94
1 file changed+12−12
tests/benchmarks/Equality.hs+12−12
tests/benchmarks/Equality.hs+12−12
@@ -6,21 +6,21 @@ import qualified Data.Text.Encoding as T
66import qualified Data.Text.Lazy as TL
77import qualified Data.Text.Lazy.Encoding as TL
88
9−text needle haystack = do
10− bs <- B.readFile haystack
11− print . length . filter (==needle) . T.lines . T.decodeUtf8 $ bs
9+text haystack = do
10+ ls <- (T.lines . T.decodeUtf8) `fmap` B.readFile haystack
11+ print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
1212
13−lazyText needle haystack = do
14− bs <- BL.readFile haystack
15− print . length . filter (==needle) . TL.lines . TL.decodeUtf8 $ bs
13+lazyText haystack = do
14+ ls <- (TL.lines . TL.decodeUtf8) `fmap` BL.readFile haystack
15+ print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
1616
17−string needle haystack = do
18− s <- readFile haystack
19− print . length . filter (==needle) . lines $ s
17+string haystack = do
18+ ls <- lines `fmap` readFile haystack
19+ print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
2020
2121main = do
2222 args <- getArgs
2323 case args of
24− ["text",n,h] -> text (T.pack n) h
25− ["lazytext",n,h] -> lazyText (TL.pack n) h
26− ["string",n,h] -> string n h
24+ ["text",h] -> text h
25+ ["lazytext",h] -> lazyText h
26+ ["string",h] -> string h