on master help sign in
Add a benchmark

--HG-- extra : convert_revision : 2a4ca7b98de10ce914e138e41179ef7f4de61e8e

commit09e803d4513a12fbaff3fd134b576fa2e3e12a38 authorBryan O'Sullivan <bos@serpentine.com> dateSat 14 Aug 2010, 23:54 (16 years ago) parente33c73c
1 file changed+25
tests/benchmarks/FileIndices.hs+25
tests/benchmarks/FileIndices.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# LANGUAGE BangPatterns #-}
2+
3+import System.Environment (getArgs)
4+import qualified Data.Text.Lazy.IO as T
5+import qualified Data.Text.Lazy as T
6+import qualified Data.Text.Lazy.Encoding as T
7+import qualified Data.ByteString.Lazy.Char8 as B
8+import qualified Data.ByteString.Char8 as BS
9+import qualified Data.ByteString.Lazy.Search as B
10+
11+text :: FilePath -> String -> IO ()
12+text file pat = T.readFile file >>= print . T.count (T.pack pat)
13+
14+textBS :: FilePath -> String -> IO ()
15+textBS file pat = B.readFile file >>= print . T.count (T.pack pat) . T.decodeUtf8
16+
17+bytestring :: FilePath -> String -> IO ()
18+bytestring file pat = B.readFile file >>= print . length . B.indices (BS.pack pat)
19+
20+main = do
21+ (name : file : pat : _) <- getArgs
22+ case name of
23+ "bs" -> bytestring file pat
24+ "text" -> text file pat
25+ "textBS" -> textBS file pat