Commits

Bryan O'Sullivan committed cba78c6

Encoding performance: compare like with like.

Comments (0)

Files changed (2)

benchmarks/CompareWithJSON.hs

 {-# OPTIONS_GHC -fno-warn-orphans #-}
 
+import Blaze.ByteString.Builder (toLazyByteString)
+import Blaze.ByteString.Builder.Char.Utf8 (fromString)
 import Control.DeepSeq (NFData(rnf))
 import Criterion.Main
 import qualified Data.Aeson as A
               Just v -> v
               Nothing -> error "fail to parse via Aeson"
 
+encodeJ :: J.JSValue -> BL.ByteString
+encodeJ = toLazyByteString . fromString . J.encode
+
 main :: IO ()
 main = do
   let enFile = "json-data/twitter100.json"
     , bgroup "encode" [
         bgroup "en" [
           bench "aeson" $ nf A.encode (decodeA enA)
-        , bench "json"  $ nf J.encode (decodeJ enJ)
+        , bench "json"  $ nf encodeJ (decodeJ enJ)
         ]
       , bgroup "jp" [
           bench "aeson" $ nf A.encode (decodeA jpA)
-        , bench "json"  $ nf J.encode (decodeJ jpJ)
+        , bench "json"  $ nf encodeJ (decodeJ jpJ)
         ]
       ]
     ]

benchmarks/aeson-benchmarks.cabal

   build-depends:
     aeson == 0.4.0.0,
     base,
+    blaze-builder,
     bytestring,
     criterion,
     json