on master help sign in
Improve compare-with-json benchmark
commita1044ddf60dff9826ccd21f50c7457b73e5996b8 authorOleg Grenrus <oleg.grenrus@iki.fi> dateTue 11 Jul 2017, 17:06 (9 years ago) parent2bc6f22
5 files changed+62−14
benchmarks/AesonMap.hs+6−6 benchmarks/CompareWithJSON.hs+32−7 benchmarks/Dates.hs+1 benchmarks/aeson-benchmarks.cabal+17 stack-bench.yaml+6−1
benchmarks/AesonMap.hs+6−6
@@ -160,7 +160,7 @@ benchDecodeHM name val = bgroup name
160160 , bench "Identity" $ nf (decodeHMB proxyT1) val
161161 , bench "Coerce" $ nf (decodeHMB proxyT2) val
162162 , bench "Parser" $ nf (decodeHMB proxyT3) val
163− , bench "aeson-0.11" $ nf (decodeHMA proxyText) val
163+ , bench "aeson-hackage" $ nf (decodeHMA proxyText) val
164164 , bench "Tagged Text" $ nf (decodeHMB $ proxyTagged proxyText) val
165165 , bench "Tagged Identity" $ nf (decodeHMB $ proxyTagged proxyT1) val
166166 , bench "Tagged Coerce" $ nf (decodeHMB $ proxyTagged proxyT2) val
@@ -172,11 +172,11 @@ benchDecodeMap
172172 -> LBS.ByteString
173173 -> Benchmark
174174benchDecodeMap name val = bgroup name
175− [ bench "Text" $ nf (decodeMapB proxyText) val
176− , bench "Identity" $ nf (decodeMapB proxyT1) val
177− , bench "Coerce" $ nf (decodeMapB proxyT2) val
178− , bench "Parser" $ nf (decodeMapB proxyT3) val
179− , bench "aeson-0.11" $ nf (decodeMapA proxyText) val
175+ [ bench "Text" $ nf (decodeMapB proxyText) val
176+ , bench "Identity" $ nf (decodeMapB proxyT1) val
177+ , bench "Coerce" $ nf (decodeMapB proxyT2) val
178+ , bench "Parser" $ nf (decodeMapB proxyT3) val
179+ , bench "aeson-hackage" $ nf (decodeMapA proxyText) val
180180 ]
181181
182182benchEncodeHM
benchmarks/CompareWithJSON.hs+32−7
@@ -1,3 +1,4 @@
1+{-# LANGUAGE PackageImports #-}
12{-# OPTIONS_GHC -fno-warn-orphans #-}
23
34module Main (main) where
@@ -10,8 +11,11 @@ import Blaze.ByteString.Builder.Char.Utf8 (fromString)
1011import Control.DeepSeq (NFData(rnf))
1112import Criterion.Main
1213import Data.Maybe (fromMaybe)
13−import qualified Data.Aeson as A
14−import qualified Data.Aeson.Text as A
14+import qualified "aeson-benchmarks" Data.Aeson as A
15+import qualified "aeson-benchmarks" Data.Aeson.Text as A
16+import qualified "aeson-benchmarks" Data.Aeson.Parser.Internal as I
17+import qualified "aeson" Data.Aeson as B
18+import qualified Data.ByteString as BS
1519import qualified Data.ByteString.Lazy as BL
1620import qualified Data.Text.Lazy as TL
1721import qualified Data.Text.Lazy.Builder as TLB
@@ -41,6 +45,19 @@ decodeA s = fromMaybe (error "fail to parse via Aeson") $ A.decode s
4145decodeA' :: BL.ByteString -> A.Value
4246decodeA' s = fromMaybe (error "fail to parse via Aeson") $ A.decode' s
4347
48+decodeAS :: BS.ByteString -> A.Value
49+decodeAS s = fromMaybe (error "fail to parse via Aeson") $ A.decodeStrict' s
50+
51+decodeB :: BL.ByteString -> B.Value
52+decodeB s = fromMaybe (error "fail to parse via Aeson") $ B.decode s
53+
54+decodeBS :: BS.ByteString -> B.Value
55+decodeBS s = fromMaybe (error "fail to parse via Aeson") $ B.decodeStrict' s
56+
57+decodeIP :: BL.ByteString -> A.Value
58+decodeIP s = fromMaybe (error "fail to parse via Parser.decodeWith") $
59+ I.decodeWith I.jsonEOF A.fromJSON s
60+
4461encodeJ :: J.JSValue -> BL.ByteString
4562encodeJ = toLazyByteString . fromString . J.encode
4663
@@ -55,19 +72,27 @@ main = do
5572 let enFile = "json-data/twitter100.json"
5673 jpFile = "json-data/jp100.json"
5774 enA <- BL.readFile enFile
75+ enS <- BS.readFile enFile
5876 enJ <- readFile enFile
5977 jpA <- BL.readFile jpFile
78+ jpS <- BS.readFile jpFile
6079 jpJ <- readFile jpFile
6180 defaultMain [
6281 bgroup "decode" [
6382 bgroup "en" [
64− bench "aeson/lazy" $ nf decodeA enA
65− , bench "aeson/strict" $ nf decodeA' enA
66− , bench "json" $ nf decodeJ enJ
83+ bench "aeson/lazy" $ nf decodeA enA
84+ , bench "aeson/strict" $ nf decodeA' enA
85+ , bench "aeson/stricter" $ nf decodeAS enS
86+ , bench "aeson/hackage" $ nf decodeB enA
87+ , bench "aeson/hackage'" $ nf decodeBS enS
88+ , bench "aeson/parser" $ nf decodeIP enA
89+ , bench "json" $ nf decodeJ enJ
6790 ]
6891 , bgroup "jp" [
69− bench "aeson" $ nf decodeA jpA
70− , bench "json" $ nf decodeJ jpJ
92+ bench "aeson" $ nf decodeA jpA
93+ , bench "aeson/stricter" $ nf decodeAS jpS
94+ , bench "aeson/hackage" $ nf decodeB jpA
95+ , bench "json" $ nf decodeJ jpJ
7196 ]
7297 ]
7398 , bgroup "encode" [
benchmarks/Dates.hs+1
@@ -1,3 +1,4 @@
1+{-# OPTIONS_GHC -fsimpl-tick-factor=0 #-}
12module Main (main) where
23
34import Prelude ()
benchmarks/aeson-benchmarks.cabal+17
@@ -83,6 +83,13 @@ executable aeson-benchmark-compare
8383 main-is: Compare.hs
8484 hs-source-dirs: ../examples .
8585 ghc-options: -Wall -O2 -rtsopts
86+ other-modules:
87+ Compare.BufferBuilder
88+ Compare.JsonBench
89+ Compare.JsonBuilder
90+ Twitter
91+ Twitter.Manual
92+ Typed.Common
8693 build-depends:
8794 aeson-benchmarks,
8895 base,
@@ -116,6 +123,14 @@ executable aeson-benchmark-typed
116123 -- We must help ourself in situations when there is both
117124 -- aeson and aeson-benchmakrs
118125 cpp-options: -DHAS_BOTH_AESON_AND_BENCHMARKS
126+ other-modules:
127+ Twitter
128+ Twitter.Manual
129+ Twitter.TH
130+ Typed.Common
131+ Typed.Generic
132+ Typed.Manual
133+ Typed.TH
119134 build-depends:
120135 aeson,
121136 aeson-benchmarks,
@@ -136,7 +151,9 @@ executable aeson-benchmark-typed
136151executable aeson-benchmark-compare-with-json
137152 main-is: CompareWithJSON.hs
138153 ghc-options: -Wall -O2 -rtsopts
154+ cpp-options: -DHAS_BOTH_AESON_AND_BENCHMARKS
139155 build-depends:
156+ aeson,
140157 aeson-benchmarks,
141158 base,
142159 base-compat,
stack-bench.yaml+6−1
@@ -1,7 +1,12 @@
11resolver: lts-8.5
22packages:
3−- '.'
3+# We use aeson in the snapshot to
4+# - avoid recompilation of criterion
5+# - compare against it
6+
7+# - '.'
48- benchmarks
59extra-deps:
10+- aeson-1.2.1.0
611- quickcheck-instances-0.3.14
712- th-abstraction-0.2.2.0