Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Encoding performance: compare like with like.

  • Loading branch information...
commit 833c8fdee2881cd7312beb5021c7b36b8f6318e3 1 parent 677dad5
@bos authored
View
9 benchmarks/CompareWithJSON.hs
@@ -1,5 +1,7 @@
{-# 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
@@ -33,6 +35,9 @@ decodeA s = case A.decode s of
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"
@@ -55,11 +60,11 @@ main = do
, 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)
]
]
]
View
1  benchmarks/aeson-benchmarks.cabal
@@ -10,6 +10,7 @@ executable aeson-benchmark-compare-with-json
build-depends:
aeson == 0.4.0.0,
base,
+ blaze-builder,
bytestring,
criterion,
json
Please sign in to comment.
Something went wrong with that request. Please try again.