on master help sign in
Make the benchmarks fairer.
commitd84827f2cf4a4238caadf79797e63a0e090a97d9 authorBryan O'Sullivan <bos@serpentine.com> dateThu 22 Dec 2011, 09:34 (15 years ago) parent17013cc
1 file changed+11−13
benchmarks/CompareWithJSON.hs+11−13
benchmarks/CompareWithJSON.hs+11−13
@@ -1,11 +1,11 @@
1−{-# OPTIONS_GHC -fno-warn-orphans#-}
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
22
3+import Control.DeepSeq (NFData(rnf))
34import Criterion.Main
4−import Control.DeepSeq
5−import Data.Int
5+import qualified Data.Aeson as A
66import qualified Data.ByteString.Lazy as BL
7+import qualified Data.ByteString.Lazy.Internal as BL
78import qualified Text.JSON as J
8−import qualified Data.Aeson as A
99
1010instance (NFData v) => NFData (J.JSObject v) where
1111 rnf o = rnf (J.fromJSObject o)
@@ -18,11 +18,9 @@ instance NFData J.JSValue where
1818 rnf (J.JSArray lst) = rnf lst
1919 rnf (J.JSObject o) = rnf o
2020
21−encodeJ :: J.JSValue -> Int
22−encodeJ = length . J.encode
23−
24−encodeA :: A.Value -> Int64
25−encodeA = BL.length . A.encode
21+instance NFData BL.ByteString where
22+ rnf (BL.Chunk _ bs) = rnf bs
23+ rnf BL.Empty = ()
2624
2725decodeJ :: String -> J.JSValue
2826decodeJ s =
@@ -31,9 +29,9 @@ decodeJ s =
3129 J.Error _ -> error "fail to parse via JSON"
3230
3331decodeA :: BL.ByteString -> A.Value
34−decodeA s = case A.decode' s of
35− Nothing -> error "fail to parse via Aeson"
32+decodeA s = case A.decode s of
3633 Just v -> v
34+ Nothing -> error "fail to parse via Aeson"
3735
3836jsonData :: FilePath
3937jsonData = "json-data/jp100.json"
@@ -48,7 +46,7 @@ main = do
4846 bgroup "decode" [ bench "json" $ nf decodeJ js
4947 , bench "aeson" $ nf decodeA as
5048 ],
51− bgroup "encode" [ bench "json" $ nf encodeJ jdata
52− , bench "aeson" $ nf encodeA adata
49+ bgroup "encode" [ bench "json" $ nf J.encode jdata
50+ , bench "aeson" $ nf A.encode adata
5351 ]
5452 ]