From bcbe0d905fc7e1ca6b29e4b398e455c8c60e399d Mon Sep 17 00:00:00 2001
From: "iavor.diatchki" <iavor.diatchki@gmail.com>
Date: Mon, 10 Mar 2008 09:31:14 -0700
Subject: [PATCH] Add parameters to testing program

darcs-hash:20080310163114-5035a-0edd1f2cb9cfc78e4be7fc8a398d90ff325ef5e2.gz
---
 tests/BenchBytestring.hs | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/tests/BenchBytestring.hs b/tests/BenchBytestring.hs
index 48c669b..c38c586 100644
--- a/tests/BenchBytestring.hs
+++ b/tests/BenchBytestring.hs
@@ -1,11 +1,24 @@
 import qualified Data.ByteString      as S
 import qualified Data.ByteString.Lazy as L
 import qualified Data.String.UTF8     as UTF8
+import qualified Codec.Binary.UTF8.String as List
 
+import System.Environment(getArgs)
 import System.IO
 import Data.Word
 
-main  = main4
+main  = mapM_ run_test =<< getArgs
+
+run_test x  = case reads x of
+                [(n,"")] | n < test_num -> tests !! n
+                _ -> hPutStrLn stderr ("Invalid test: " ++ x)
+
+tests     = [ main0, main1, main2, main3, main4 ]
+test_num  = length tests
+
+
+main0 = do putStrLn "Correctness: Data.ByteString"
+           putStrLn ("Errors: " ++ show encodeDecodeTest)
 
 main1 = do putStrLn "Speed: Data.ByteString"
            txt <- S.readFile "test"
@@ -21,8 +34,11 @@ main3 = do putStrLn "Speed: [Word8]"
                bytes = map (fromIntegral . fromEnum) txt
            print (UTF8.length $ UTF8.fromRep bytes)
 
-main4 = do putStrLn "Correctness: Data.ByteString"
-           print encodeDecodeTest
+main4 = do putStrLn "Speed: [Word8] (direct)"
+           txt <- hGetContents =<< openBinaryFile "test" ReadMode
+           let bytes :: [Word8]
+               bytes = map (fromIntegral . fromEnum) txt
+           print (length $ List.decode bytes)
 
 encodeDecodeTest :: String
 encodeDecodeTest =
-- 
GitLab