[commit: packages/binary] master: Compare Put with Data.ByteString.Builder in put benchmark. (31d91b4)

git at git.haskell.org git at git.haskell.org
Tue Apr 19 20:30:32 UTC 2016


Repository : ssh://git@git.haskell.org/binary

On branch  : master
Link       : http://git.haskell.org/packages/binary.git/commitdiff/31d91b407bf3fa554a502981df88b31dafa98184

>---------------------------------------------------------------

commit 31d91b407bf3fa554a502981df88b31dafa98184
Author: Lennart Kolmodin <kolmodin at gmail.com>
Date:   Sat Apr 9 13:41:57 2016 +0200

    Compare Put with Data.ByteString.Builder in put benchmark.


>---------------------------------------------------------------

31d91b407bf3fa554a502981df88b31dafa98184
 benchmarks/Put.hs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/benchmarks/Put.hs b/benchmarks/Put.hs
index c3cae43..6f317c0 100644
--- a/benchmarks/Put.hs
+++ b/benchmarks/Put.hs
@@ -11,6 +11,7 @@ import qualified Data.ByteString.Lazy as L
 
 import Data.Binary
 import Data.Binary.Put
+import Data.ByteString.Builder as BB
 
 main :: IO ()
 main = do
@@ -36,12 +37,16 @@ main = do
       bench "[small String]" $ whnf (run . put) smallStrings,
 
       bench "Word8s" $ whnf (run . fromWord8s) word8s,
+      bench "Word8s builder" $ whnf (L.length . toLazyByteString . fromWord8sBuilder) word8s,
       bench "[Word8]" $ whnf (run . put) word8s,
       bench "Word16s" $ whnf (run . fromWord16s) word16s,
+      bench "Word16s builder" $ whnf (L.length . toLazyByteString . fromWord16sBuilder) word16s,
       bench "[Word16]" $ whnf (run . put) word16s,
       bench "Word32s" $ whnf (run . fromWord32s) word32s,
+      bench "Word32s builder" $ whnf (L.length . toLazyByteString . fromWord32sBuilder) word32s,
       bench "[Word32]" $ whnf (run . put) word32s,
       bench "Word64s" $ whnf (run . fromWord64s) word64s,
+      bench "Word64s builder" $ whnf (L.length . toLazyByteString . fromWord64sBuilder) word64s,
       bench "[Word64]" $ whnf (run . put) word64s
     ]
   where
@@ -103,15 +108,30 @@ fromWord8s :: [Word8] -> Put
 fromWord8s [] = return ()
 fromWord8s (x:xs) = put x >> fromWord8s xs
 
+fromWord8sBuilder :: [Word8] -> BB.Builder
+fromWord8sBuilder [] = mempty
+fromWord8sBuilder (x:xs) = BB.word8 x `mappend` fromWord8sBuilder xs
+
 fromWord16s :: [Word16] -> Put
 fromWord16s [] = return ()
 fromWord16s (x:xs) = put x >> fromWord16s xs
 
+fromWord16sBuilder :: [Word16] -> BB.Builder
+fromWord16sBuilder [] = mempty
+fromWord16sBuilder (x:xs) = BB.word16BE x `mappend` fromWord16sBuilder xs
+
 fromWord32s :: [Word32] -> Put
 fromWord32s [] = return ()
 fromWord32s (x:xs) = put x >> fromWord32s xs
 
+fromWord32sBuilder :: [Word32] -> BB.Builder
+fromWord32sBuilder [] = mempty
+fromWord32sBuilder (x:xs) = BB.word32BE x `mappend` fromWord32sBuilder xs
+
 fromWord64s :: [Word64] -> Put
 fromWord64s [] = return ()
 fromWord64s (x:xs) = put x >> fromWord64s xs
 
+fromWord64sBuilder :: [Word64] -> BB.Builder
+fromWord64sBuilder [] = mempty
+fromWord64sBuilder (x:xs) = BB.word64BE x `mappend` fromWord64sBuilder xs



More information about the ghc-commits mailing list