Browse files

Add parameters to testing program

darcs-hash:20080310163114-5035a-0edd1f2cb9cfc78e4be7fc8a398d90ff325ef5e2.gz
  • Loading branch information...
1 parent fcbc786 commit bcbe0d905fc7e1ca6b29e4b398e455c8c60e399d @yav yav committed Mar 10, 2008
Showing with 19 additions and 3 deletions.
  1. +19 −3 tests/BenchBytestring.hs
View
22 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 =

0 comments on commit bcbe0d9

Please sign in to comment.