1{-# OPTIONS_GHC -fno-warn-orphans #-}
3import Blaze.ByteString.Builder (toLazyByteString)
4import Blaze.ByteString.Builder.Char.Utf8 (fromString)
5import Control.DeepSeq (NFData(rnf))
7import qualified Data.Aeson.Encode as A
8import qualified Data.Aeson as A
9import qualified Data.ByteString.Lazy as BL
10import qualified Text.JSON as J
11import qualified Data.Text.Lazy as TL
12import qualified Data.Text.Lazy.Builder as TLB
13import qualified Data.Text.Lazy.Encoding as TLE
15instance (NFData v) => NFData (J.JSObject v) where
16 rnf o = rnf (J.fromJSObject o)
18instance NFData J.JSValue where
20 rnf (J.JSBool b) = rnf b
21 rnf (J.JSRational a b) = rnf a `seq` rnf b `seq` ()
22 rnf (J.JSString s) = rnf (J.fromJSString s)
23 rnf (J.JSArray lst) = rnf lst
24 rnf (J.JSObject o) = rnf o
26decodeJ :: String -> J.JSValue
28 case J.decodeStrict s of
30 J.Error _ -> error "fail to parse via JSON"
32decodeA :: BL.ByteString -> A.Value
33decodeA s = case A.decode s of
35 Nothing -> error "fail to parse via Aeson"
37encodeJ :: J.JSValue -> BL.ByteString
38encodeJ = toLazyByteString . fromString . J.encode
40encodeToText :: A.Value -> TL.Text
41encodeToText = TLB.toLazyText . A.encodeToTextBuilder . A.toJSON
43encodeViaText :: A.Value -> BL.ByteString
44encodeViaText = TLE.encodeUtf8 . encodeToText
48 let enFile = "json-data/twitter100.json"
49 jpFile = "json-data/jp100.json"
50 enA <- BL.readFile enFile
51 enJ <- readFile enFile
52 jpA <- BL.readFile jpFile
53 jpJ <- readFile jpFile
57 bench "aeson" $ nf decodeA enA
58 , bench "json" $ nf decodeJ enJ
61 bench "aeson" $ nf decodeA jpA
62 , bench "json" $ nf decodeJ jpJ
67 bench "aeson-to-bytestring" $ nf A.encode (decodeA enA)
68 , bench "aeson-via-text-to-bytestring" $ nf encodeViaText (decodeA enA)
69 , bench "aeson-to-text" $ nf encodeToText (decodeA enA)
70 , bench "json" $ nf encodeJ (decodeJ enJ)
73 bench "aeson-to-bytestring" $ nf A.encode (decodeA jpA)
74 , bench "aeson-via-text-to-bytestring" $ nf encodeViaText (decodeA jpA)
75 , bench "aeson-to-text" $ nf encodeToText (decodeA jpA)
76 , 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