[commit: packages/binary] ghc-head: Add a Cereal bracket test. (228bdcc)
git at git.haskell.org
git at git.haskell.org
Fri Aug 30 15:20:27 CEST 2013
Repository : ssh://git@git.haskell.org/binary
On branch : ghc-head
Link : http://git.haskell.org/?p=packages/binary.git;a=commit;h=228bdcc7926866ab05224b3183a7fb1a0822ceed
>---------------------------------------------------------------
commit 228bdcc7926866ab05224b3183a7fb1a0822ceed
Author: Lennart Kolmodin <kolmodin at google.com>
Date: Tue Mar 5 15:48:33 2013 +0400
Add a Cereal bracket test.
>---------------------------------------------------------------
228bdcc7926866ab05224b3183a7fb1a0822ceed
benchmarks/Get.hs | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/benchmarks/Get.hs b/benchmarks/Get.hs
index f43dabb..57616c9 100644
--- a/benchmarks/Get.hs
+++ b/benchmarks/Get.hs
@@ -53,8 +53,10 @@ main = do
whnf (checkBracket . runAttoL bracketParser_atto) brackets
, bench "Attoparsec lazy-bs brackets 100kb in 100 byte chunks" $
whnf (checkBracket . runAttoL bracketParser_atto) bracketsInChunks
- , bench "Attoparsec strict-bs brackets 10M0kb one chunk" $
+ , bench "Attoparsec strict-bs brackets 100kb" $
whnf (checkBracket . runAtto bracketParser_atto) $ S.concat (L.toChunks brackets)
+ , bench "Cereal strict-bs brackets 100kb" $
+ whnf (checkBracket . runCereal bracketParser_cereal) $ S.concat (L.toChunks brackets)
, bench "Binary getStruct4 1MB struct of 4 word8" $
whnf (runTest (getStruct4 mega)) oneMegabyteLBS
, bench "Cereal getStruct4 1MB struct of 4 word8" $
@@ -89,7 +91,9 @@ checkBracket x | x == bracketCount = x
| otherwise = error "argh!"
runTest decoder inp = runGet decoder inp
-runCereal decoder inp = Cereal.runGet decoder inp
+runCereal decoder inp = case Cereal.runGet decoder inp of
+ Right a -> a
+ Left err -> error err
runAtto decoder inp = case A.parseOnly decoder inp of
Right a -> a
Left err -> error err
@@ -128,6 +132,15 @@ bracketParser = cont <|> return 0
return $! sum n + 1)
return $! sum v
+bracketParser_cereal :: Cereal.Get Int
+bracketParser_cereal = cont <|> return 0
+ where
+ cont = do v <- some ( do 40 <- Cereal.getWord8
+ n <- many cont
+ 41 <- Cereal.getWord8
+ return $! sum n + 1)
+ return $! sum v
+
bracketParser_atto :: A.Parser Int
bracketParser_atto = cont <|> return 0
where
More information about the ghc-commits
mailing list