Skip to content

Commit a1044dd

Browse files
committed
Improve compare-with-json benchmark
1 parent 2bc6f22 commit a1044dd

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

benchmarks/AesonMap.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
174174
benchDecodeMap 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

182182
benchEncodeHM

benchmarks/CompareWithJSON.hs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE PackageImports #-}
12
{-# OPTIONS_GHC -fno-warn-orphans #-}
23

34
module Main (main) where
@@ -10,8 +11,11 @@ import Blaze.ByteString.Builder.Char.Utf8 (fromString)
1011
import Control.DeepSeq (NFData(rnf))
1112
import Criterion.Main
1213
import 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
1519
import qualified Data.ByteString.Lazy as BL
1620
import qualified Data.Text.Lazy as TL
1721
import qualified Data.Text.Lazy.Builder as TLB
@@ -41,6 +45,19 @@ decodeA s = fromMaybe (error "fail to parse via Aeson") $ A.decode s
4145
decodeA' :: BL.ByteString -> A.Value
4246
decodeA' 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+
4461
encodeJ :: J.JSValue -> BL.ByteString
4562
encodeJ = 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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS_GHC -fsimpl-tick-factor=0 #-}
12
module Main (main) where
23

34
import Prelude ()

benchmarks/aeson-benchmarks.cabal

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
136151
executable 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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
resolver: lts-8.5
22
packages:
3-
- '.'
3+
# We use aeson in the snapshot to
4+
# - avoid recompilation of criterion
5+
# - compare against it
6+
7+
# - '.'
48
- benchmarks
59
extra-deps:
10+
- aeson-1.2.1.0
611
- quickcheck-instances-0.3.14
712
- th-abstraction-0.2.2.0

0 commit comments

Comments
 (0)