1{-# OPTIONS_GHC -fno-warn-orphans #-}
3module Main (main) where
8import Blaze.ByteString.Builder (toLazyByteString)
9import Blaze.ByteString.Builder.Char.Utf8 (fromString)
10import Control.DeepSeq (NFData(rnf))
12import Data.Maybe (fromMaybe)
13import qualified Data.Aeson as A
14import qualified Data.Aeson.Text as A
15import qualified Data.Aeson.Parser.Internal as I
16import qualified Data.ByteString as BS
17import qualified Data.ByteString.Lazy as BL
18import qualified Data.Text.Lazy as TL
19import qualified Data.Text.Lazy.Builder as TLB
20import qualified Data.Text.Lazy.Encoding as TLE
21import qualified Text.JSON as J
23instance (NFData v) => NFData (J.JSObject v) where
24 rnf o = rnf (J.fromJSObject o)
26instance NFData J.JSValue where
28 rnf (J.JSBool b) = rnf b
29 rnf (J.JSRational a b) = rnf a `seq` rnf b `seq` ()
30 rnf (J.JSString s) = rnf (J.fromJSString s)
31 rnf (J.JSArray lst) = rnf lst
32 rnf (J.JSObject o) = rnf o
34decodeJ :: String -> J.JSValue
36 case J.decodeStrict s of
38 J.Error _ -> error "fail to parse via JSON"
40decode :: BL.ByteString -> A.Value
41decode s = fromMaybe (error "fail to parse via Aeson") $ A.decode s
43decode' :: BL.ByteString -> A.Value
44decode' s = fromMaybe (error "fail to parse via Aeson") $ A.decode' s
46decodeS :: BS.ByteString -> A.Value
47decodeS s = fromMaybe (error "fail to parse via Aeson") $ A.decodeStrict' s
49decodeIP :: BL.ByteString -> A.Value
50decodeIP s = fromMaybe (error "fail to parse via Parser.decodeWith") $
51 I.decodeWith I.jsonEOF A.fromJSON s
53encodeJ :: J.JSValue -> BL.ByteString
54encodeJ = toLazyByteString . fromString . J.encode
56encodeToText :: A.Value -> TL.Text
57encodeToText = TLB.toLazyText . A.encodeToTextBuilder . A.toJSON
59encodeViaText :: A.Value -> BL.ByteString
60encodeViaText = TLE.encodeUtf8 . encodeToText
64 let enFile = "json-data/twitter100.json"
65 jpFile = "json-data/jp100.json"
66 enA <- BL.readFile enFile
67 enS <- BS.readFile enFile
68 enJ <- readFile enFile
69 jpA <- BL.readFile jpFile
70 jpS <- BS.readFile jpFile
71 jpJ <- readFile jpFile
75 bench "aeson/lazy" $ nf decode enA
76 , bench "aeson/strict" $ nf decode' enA
77 , bench "aeson/stricter" $ nf decodeS enS
78 , bench "aeson/parser" $ nf decodeIP enA
79 , bench "json" $ nf decodeJ enJ
82 bench "aeson" $ nf decode jpA
83 , bench "aeson/stricter" $ nf decodeS jpS
84 , bench "json" $ nf decodeJ jpJ
89 bench "aeson-to-bytestring" $ nf A.encode (decode enA)
90 , bench "aeson-via-text-to-bytestring" $ nf encodeViaText (decode enA)
91 , bench "aeson-to-text" $ nf encodeToText (decode enA)
92 , bench "json" $ nf encodeJ (decodeJ enJ)
95 bench "aeson-to-bytestring" $ nf A.encode (decode jpA)
96 , bench "aeson-via-text-to-bytestring" $ nf encodeViaText (decode jpA)
97 , bench "aeson-to-text" $ nf encodeToText (decode jpA)
98 , 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