summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench/Main.hs23
-rw-r--r--src/Data/BEncode.hs2
2 files changed, 24 insertions, 1 deletions
diff --git a/bench/Main.hs b/bench/Main.hs
index cc64d4b..08ebab8 100644
--- a/bench/Main.hs
+++ b/bench/Main.hs
@@ -6,6 +6,7 @@ import Data.Maybe
6import Data.Attoparsec.ByteString as Atto 6import Data.Attoparsec.ByteString as Atto
7import Data.ByteString as B 7import Data.ByteString as B
8import Data.ByteString.Lazy as BL 8import Data.ByteString.Lazy as BL
9import Data.List as L
9import Criterion.Main 10import Criterion.Main
10import System.Environment 11import System.Environment
11 12
@@ -64,4 +65,26 @@ main = do
64 torrentFile 65 torrentFile
65 , bench "decode+encode/bencoding" $ nf (C.encode . getRight . C.decode) 66 , bench "decode+encode/bencoding" $ nf (C.encode . getRight . C.decode)
66 torrentFile 67 torrentFile
68
69 , bench "list10000int/bencode/encode" $ nf
70 (A.bPack . A.BList . L.map (A.BInt . fromIntegral))
71 [0..10000 :: Int]
72
73 , bench "list10000int/attobencode/encode" $ nf B.encode [1..20000 :: Int]
74 , bench "list10000int/bencoding/encode" $ nf C.encoded [1..20000 :: Int]
75
76
77 , let d = A.bPack $ A.BList $
78 L.map A.BInt (L.replicate 1000 (0 :: Integer))
79 in d `seq` (bench "list10000int/bencode/decode" $ nf
80 (fromJust . A.bRead :: BL.ByteString -> A.BEncode) d)
81
82 , let d = BL.toStrict (C.encoded (L.replicate 10000 ()))
83 in d `seq` (bench "list10000unit/bencoding/decode" $ nf
84 (C.decoded :: B.ByteString -> Either String [()]) d)
85
86 , let d = BL.toStrict (C.encoded (L.replicate 10000 (0 :: Int)))
87 in d `seq` (bench "list10000int/bencoding/decode" $ nf
88 (C.decoded :: B.ByteString -> Either String [Int]) d)
89
67 ] 90 ]
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs
index d4997fb..dd94f8c 100644
--- a/src/Data/BEncode.hs
+++ b/src/Data/BEncode.hs
@@ -403,7 +403,7 @@ parser = valueP
403 P.anyChar 403 P.anyChar
404 (BDict . M.fromDistinctAscList <$> many ((,) <$> stringP <*> valueP)) 404 (BDict . M.fromDistinctAscList <$> many ((,) <$> stringP <*> valueP))
405 <* P.anyChar 405 <* P.anyChar
406 _ -> fail "" 406 _ -> fail "Unable to parse bencode: unknown tag"
407 407
408 stringP :: Parser ByteString 408 stringP :: Parser ByteString
409 stringP = do 409 stringP = do