Skip to content

Commit

Permalink
Add parameters to testing program
Browse files Browse the repository at this point in the history
darcs-hash:20080310163114-5035a-0edd1f2cb9cfc78e4be7fc8a398d90ff325ef5e2.gz
  • Loading branch information
yav committed Mar 10, 2008
1 parent fcbc786 commit bcbe0d9
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions 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"
Expand All @@ -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 =
Expand Down

0 comments on commit bcbe0d9

Please sign in to comment.