1{-# LANGUAGE NoImplicitPrelude #-}
3{-# OPTIONS_GHC -fno-warn-orphans #-}
5module Main (main) where
9import Blaze.ByteString.Builder (toLazyByteString)
10import Blaze.ByteString.Builder.Char.Utf8 (fromString)
11import Control.DeepSeq (NFData(rnf))
13import Data.Maybe (fromMaybe)
14import qualified Data.Aeson as A
15import qualified Data.Aeson.Text as A
16import qualified Data.Aeson.Parser.Internal as I
17import qualified Data.ByteString as BS
18import qualified Data.ByteString.Lazy as BL
19import qualified Data.Text.Lazy as TL
20import qualified Data.Text.Lazy.Builder as TLB
21import qualified Data.Text.Lazy.Encoding as TLE
22import qualified Text.JSON as J
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"
41decode :: BL.ByteString -> A.Value
42decode s = fromMaybe (error "fail to parse via Aeson") $ A.decode s
44decode' :: BL.ByteString -> A.Value
45decode' s = fromMaybe (error "fail to parse via Aeson") $ A.decode' s
47decodeS :: BS.ByteString -> A.Value
48decodeS s = fromMaybe (error "fail to parse via Aeson") $ A.decodeStrict' s
50decodeIP :: BL.ByteString -> A.Value
51decodeIP s = fromMaybe (error "fail to parse via Parser.decodeWith") $
52 I.decodeWith I.jsonEOF A.fromJSON s
54encodeJ :: J.JSValue -> BL.ByteString
55encodeJ = toLazyByteString . fromString . J.encode
57encodeToText :: A.Value -> TL.Text
58encodeToText = TLB.toLazyText . A.encodeToTextBuilder . A.toJSON
60encodeViaText :: A.Value -> BL.ByteString
61encodeViaText = TLE.encodeUtf8 . encodeToText
65 let enFile = "json-data/twitter100.json"
66 jpFile = "json-data/jp100.json"
67 enA <- BL.readFile enFile
68 enS <- BS.readFile enFile
69 enJ <- readFile enFile
70 jpA <- BL.readFile jpFile
71 jpS <- BS.readFile jpFile
72 jpJ <- readFile jpFile
76 bench "aeson/lazy" $ nf decode enA
77 , bench "aeson/strict" $ nf decode' enA
78 , bench "aeson/stricter" $ nf decodeS enS
79 , bench "aeson/parser" $ nf decodeIP enA
80 , bench "json" $ nf decodeJ enJ
83 bench "aeson" $ nf decode jpA
84 , bench "aeson/stricter" $ nf decodeS jpS
85 , bench "json" $ nf decodeJ jpJ
90 bench "aeson-to-bytestring" $ nf A.encode (decode enA)
91 , bench "aeson-via-text-to-bytestring" $ nf encodeViaText (decode enA)
92 , bench "aeson-to-text" $ nf encodeToText (decode enA)
93 , bench "json" $ nf encodeJ (decodeJ enJ)
96 bench "aeson-to-bytestring" $ nf A.encode (decode jpA)
97 , bench "aeson-via-text-to-bytestring" $ nf encodeViaText (decode jpA)
98 , bench "aeson-to-text" $ nf encodeToText (decode jpA)
99 , 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