Commits

Bryan O'Sullivan  committed 59be621

Simplify the equality benchmark

  • Participants
  • Parent commits 04410b4

Comments (0)

Files changed (1)

File tests/benchmarks/Equality.hs

 import qualified Data.Text.Lazy as TL
 import qualified Data.Text.Lazy.Encoding as TL
 
-text needle haystack = do
-  bs <- B.readFile haystack
-  print . length . filter (==needle) . T.lines . T.decodeUtf8 $ bs
+text haystack = do
+  ls <- (T.lines . T.decodeUtf8) `fmap` B.readFile haystack
+  print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
 
-lazyText needle haystack = do
-  bs <- BL.readFile haystack
-  print . length . filter (==needle) . TL.lines . TL.decodeUtf8 $ bs
+lazyText haystack = do
+  ls <- (TL.lines . TL.decodeUtf8) `fmap` BL.readFile haystack
+  print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
 
-string needle haystack = do
-  s <- readFile haystack
-  print . length . filter (==needle) . lines $ s
+string haystack = do
+  ls <- lines `fmap` readFile haystack
+  print . sum . map (\needle -> length . filter (==needle) $ ls) $ take 100 ls
 
 main = do
   args <- getArgs
   case args of
-    ["text",n,h] -> text (T.pack n) h
-    ["lazytext",n,h] -> lazyText (TL.pack n) h
-    ["string",n,h] -> string n h
+    ["text",h] -> text h
+    ["lazytext",h] -> lazyText h
+    ["string",h] -> string h