2{-# OPTIONS_GHC -fno-warn-orphans #-}
4import Blaze.ByteString.Builder (toLazyByteString)
5import Blaze.ByteString.Builder.Char.Utf8 (fromString)
6import Control.DeepSeq (NFData(rnf))
8import qualified Data.Aeson.Encode as A
9import qualified Data.Aeson as A
10import qualified Data.ByteString.Lazy as BL
11import qualified Text.JSON as J
12import qualified Data.Text.Lazy as TL
13import qualified Data.Text.Lazy.Builder as TLB
14import qualified Data.Text.Lazy.Encoding as TLE
16#if !MIN_VERSION_bytestring(0,10,0)
17import qualified Data.ByteString.Lazy.Internal as BL
19instance NFData BL.ByteString where
20 rnf (BL.Chunk _ bs) = rnf bs
24instance (NFData v) => NFData (J.JSObject v) where
25 rnf o = rnf (J.fromJSObject o)
27instance NFData J.JSValue where
29 rnf (J.JSBool b) = rnf b
30 rnf (J.JSRational a b) = rnf a `seq` rnf b `seq` ()
31 rnf (J.JSString s) = rnf (J.fromJSString s)
32 rnf (J.JSArray lst) = rnf lst
33 rnf (J.JSObject o) = rnf o
35decodeJ :: String -> J.JSValue
37 case J.decodeStrict s of
39 J.Error _ -> error "fail to parse via JSON"
41decodeA :: BL.ByteString -> A.Value
42decodeA s = case A.decode s of
44 Nothing -> error "fail to parse via Aeson"
46encodeJ :: J.JSValue -> BL.ByteString
47encodeJ = toLazyByteString . fromString . J.encode
49#if MIN_VERSION_bytestring(0,10,4)
50encodeToText :: A.Value -> TL.Text
51encodeToText = TLB.toLazyText . A.encodeToTextBuilder . A.toJSON
53encodeViaText :: A.Value -> BL.ByteString
54encodeViaText = TLE.encodeUtf8 . encodeToText
59 let enFile = "json-data/twitter100.json"
60 jpFile = "json-data/jp100.json"
61 enA <- BL.readFile enFile
62 enJ <- readFile enFile
63 jpA <- BL.readFile jpFile
64 jpJ <- readFile jpFile
68 bench "aeson" $ nf decodeA enA
69 , bench "json" $ nf decodeJ enJ
72 bench "aeson" $ nf decodeA jpA
73 , bench "json" $ nf decodeJ jpJ
78 bench "aeson-to-bytestring" $ nf A.encode (decodeA enA)
79#if MIN_VERSION_bytestring(0,10,4)
80 , bench "aeson-via-text-to-bytestring" $ nf encodeViaText (decodeA enA)
81 , bench "aeson-to-text" $ nf encodeToText (decodeA enA)
83 , bench "json" $ nf encodeJ (decodeJ enJ)
86 bench "aeson-to-bytestring" $ nf A.encode (decodeA jpA)
87#if MIN_VERSION_bytestring(0,10,4)
88 , bench "aeson-via-text-to-bytestring" $ nf encodeViaText (decodeA jpA)
89 , bench "aeson-to-text" $ nf encodeToText (decodeA jpA)
91 , bench "json" $ nf encodeJ (decodeJ jpJ)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list