Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added CompareWithJSON benchmark from issue: #56 #57

Merged
merged 2 commits into from

2 participants

@basvandijk
Collaborator

My results on running this on benchmarks/json-data/jp100.json with GHC-7.4.1-rc1:

benchmarking decode/json
mean: 21.16657 ms, lb 20.40948 ms, ub 21.87215 ms, ci 0.950
std dev: 3.740378 ms, lb 3.458451 ms, ub 3.964592 ms, ci 0.950
variance introduced by outliers: 92.567%
variance is severely inflated by outliers

benchmarking decode/aeson
mean: 5.458151 ms, lb 5.246154 ms, ub 5.734707 ms, ci 0.950
std dev: 1.241663 ms, lb 1.011339 ms, ub 1.463769 ms, ci 0.950
found 20 outliers among 100 samples (20.0%)
  18 (18.0%) high severe
variance introduced by outliers: 95.722%
variance is severely inflated by outliers

benchmarking encode/json
mean: 1.329795 ms, lb 1.315440 ms, ub 1.375647 ms, ci 0.950
std dev: 117.6547 us, lb 35.56607 us, ub 259.4640 us, ci 0.950
found 7 outliers among 100 samples (7.0%)
  6 (6.0%) high severe
variance introduced by outliers: 74.847%
variance is severely inflated by outliers

benchmarking encode/aeson
mean: 2.087864 ms, lb 2.061921 ms, ub 2.121384 ms, ci 0.950
std dev: 150.1140 us, lb 127.2650 us, ub 201.8160 us, ci 0.950
found 24 outliers among 100 samples (24.0%)
  23 (23.0%) high mild
  1 (1.0%) high severe
variance introduced by outliers: 65.643%
variance is severely inflated by outliers
basvandijk added some commits
@basvandijk basvandijk Added CompareWithJSON benchmark from issue: #56 dcc6b73
@basvandijk basvandijk encode and decode JSValues instead of JSObjects
This is consistent with the aeson encode en decode.
This does not change the benchmark results.
38e1482
@bos bos merged commit 38e1482 into bos:master
@bos
Owner

Thanks, Bas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 21, 2011
  1. @basvandijk
  2. @basvandijk

    encode and decode JSValues instead of JSObjects

    basvandijk authored
    This is consistent with the aeson encode en decode.
    This does not change the benchmark results.
This page is out of date. Refresh to see the latest.
Showing with 54 additions and 0 deletions.
  1. +54 −0 benchmarks/CompareWithJSON.hs
View
54 benchmarks/CompareWithJSON.hs
@@ -0,0 +1,54 @@
+{-# OPTIONS_GHC -fno-warn-orphans#-}
+
+import Criterion.Main
+import Control.DeepSeq
+import Data.Int
+import qualified Data.ByteString.Lazy as BL
+import qualified Text.JSON as J
+import qualified Data.Aeson as A
+
+instance (NFData v) => NFData (J.JSObject v) where
+ rnf o = rnf (J.fromJSObject o)
+
+instance NFData J.JSValue where
+ rnf J.JSNull = ()
+ rnf (J.JSBool b) = rnf b
+ rnf (J.JSRational a b) = rnf a `seq` rnf b `seq` ()
+ rnf (J.JSString s) = rnf (J.fromJSString s)
+ rnf (J.JSArray lst) = rnf lst
+ rnf (J.JSObject o) = rnf o
+
+encodeJ :: J.JSValue -> Int
+encodeJ = length . J.encode
+
+encodeA :: A.Value -> Int64
+encodeA = BL.length . A.encode
+
+decodeJ :: String -> J.JSValue
+decodeJ s =
+ case J.decodeStrict s of
+ J.Ok v -> v
+ J.Error _ -> error "fail to parse via JSON"
+
+decodeA :: BL.ByteString -> A.Value
+decodeA s = case A.decode' s of
+ Nothing -> error "fail to parse via Aeson"
+ Just v -> v
+
+jsonData :: FilePath
+jsonData = "benchmarks/json-data/jp100.json"
+
+main :: IO ()
+main = do
+ js <- readFile jsonData
+ as <- BL.readFile jsonData
+ let jdata = decodeJ js
+ adata = decodeA as
+ (jdata, adata) `deepseq` defaultMain [
+ bgroup "decode" [ bench "json" $ nf decodeJ js
+ , bench "aeson" $ nf decodeA as
+ ],
+ bgroup "encode" [ bench "json" $ nf encodeJ jdata
+ , bench "aeson" $ nf encodeA adata
+ ]
+ ]
Something went wrong with that request. Please try again.