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 =