on master help sign in
Use the Unix cut command as a benchmark

--HG-- extra : convert_revision : f37fd16e0030a4bee8018cb687c8858c22428c76

commit9d5cf022f0e889e8ced315cbf7f3da70bbf39940 authorBryan O'Sullivan <bos@serpentine.com> dateSun 15 Aug 2010, 20:41 (16 years ago) parent0321489
1 file changed+44
tests/benchmarks/Cut.hs+44
tests/benchmarks/Cut.hsnew file+44
@@ -0,0 +1,44 @@
1+import qualified Data.ByteString.Char8 as B
2+import qualified Data.ByteString.Lazy.Char8 as BL
3+import qualified Data.Text.IO as T
4+import qualified Data.Text as T
5+import qualified Data.Text.Lazy.IO as TL
6+import qualified Data.Text.Lazy as TL
7+import Data.Int (Int64)
8+import Numeric (readDec)
9+import System.Environment (getArgs)
10+
11+bytestring file s e = do
12+ t <- B.readFile file
13+ B.putStr (cut s e t)
14+ where
15+ cut s e = B.unlines . map (B.take (e - s) . B.drop s) . B.lines
16+
17+lazyBytestring file s e = do
18+ t <- BL.readFile file
19+ BL.putStr (cut (fromIntegral s) (fromIntegral e) t)
20+ where
21+ cut s e = BL.unlines . map (BL.take (e - s) . BL.drop s) . BL.lines
22+
23+lazyText file s e = do
24+ t <- TL.readFile file
25+ TL.putStr (cut (fromIntegral s) (fromIntegral e) t)
26+ where
27+ cut s e = TL.unlines . map (TL.take (e - s) . TL.drop s) . TL.lines
28+
29+text file s e = do
30+ t <- T.readFile file
31+ T.putStr (cut s e t)
32+ where
33+ cut s e = T.unlines . map (T.take (e - s) . T.drop s) . T.lines
34+
35+main = do
36+ (name : ss : es : file : _) <- getArgs
37+ let [(s',"")] = readDec ss
38+ [(e,"")] = readDec es
39+ s = s' - 1
40+ case name of
41+ "bs" -> bytestring file s e
42+ "lbs" -> lazyBytestring file s e
43+ "ltext" -> lazyText file s e
44+ "text" -> text file s e