1
1
{-# LANGUAGE FlexibleContexts #-}
2
- {-# LANGUAGE OverloadedStrings #-}
3
- {-# LANGUAGE PackageImports #-}
4
2
{-# LANGUAGE RankNTypes #-}
5
3
6
4
{-# OPTIONS_GHC -fno-warn-orphans #-}
@@ -15,9 +13,8 @@ import Criterion.Main
15
13
import Data.Hashable
16
14
import Data.Proxy (Proxy (.. ))
17
15
import Data.Tagged (Tagged (.. ))
18
- import qualified "aeson" Data.Aeson as A
19
- import qualified "aeson-benchmarks" Data.Aeson as B
20
- import qualified "aeson-benchmarks" Data.Aeson.Types as B (fromJSONKeyCoerce )
16
+ import Data.Aeson
17
+ import Data.Aeson.Types (fromJSONKeyCoerce )
21
18
import qualified Data.ByteString.Lazy as LBS
22
19
import qualified Data.HashMap.Strict as HM
23
20
import qualified Data.Map as M
@@ -47,10 +44,10 @@ instance NFData T1 where
47
44
instance Hashable T1 where
48
45
hashWithSalt salt (T1 t) = hashWithSalt salt t
49
46
50
- instance B. FromJSON T1 where
51
- parseJSON = B. withText " T1" $ pure . T1
52
- instance B. FromJSONKey T1 where
53
- fromJSONKey = B. FromJSONKeyText T1
47
+ instance FromJSON T1 where
48
+ parseJSON = withText " T1" $ pure . T1
49
+ instance FromJSONKey T1 where
50
+ fromJSONKey = FromJSONKeyText T1
54
51
55
52
-------------------------------------------------------------------------------
56
53
-- Coerce
@@ -64,10 +61,10 @@ instance NFData T2 where
64
61
instance Hashable T2 where
65
62
hashWithSalt salt (T2 t) = hashWithSalt salt t
66
63
67
- instance B. FromJSON T2 where
68
- parseJSON = B. withText " T2" $ pure . T2
69
- instance B. FromJSONKey T2 where
70
- fromJSONKey = B. fromJSONKeyCoerce
64
+ instance FromJSON T2 where
65
+ parseJSON = withText " T2" $ pure . T2
66
+ instance FromJSONKey T2 where
67
+ fromJSONKey = fromJSONKeyCoerce
71
68
72
69
-------------------------------------------------------------------------------
73
70
-- TextParser
@@ -81,10 +78,10 @@ instance NFData T3 where
81
78
instance Hashable T3 where
82
79
hashWithSalt salt (T3 t) = hashWithSalt salt t
83
80
84
- instance B. FromJSON T3 where
85
- parseJSON = B. withText " T3" $ pure . T3
86
- instance B. FromJSONKey T3 where
87
- fromJSONKey = B. FromJSONKeyTextParser (pure . T3 )
81
+ instance FromJSON T3 where
82
+ parseJSON = withText " T3" $ pure . T3
83
+ instance FromJSONKey T3 where
84
+ fromJSONKey = FromJSONKeyTextParser (pure . T3 )
88
85
89
86
-------------------------------------------------------------------------------
90
87
-- Values
@@ -97,40 +94,30 @@ value1000 = value 1000
97
94
value10000 = value 10000
98
95
99
96
encodedValue10 :: LBS. ByteString
100
- encodedValue10 = B. encode value10
97
+ encodedValue10 = encode value10
101
98
102
99
encodedValue100 :: LBS. ByteString
103
- encodedValue100 = B. encode value100
100
+ encodedValue100 = encode value100
104
101
105
102
encodedValue1000 :: LBS. ByteString
106
- encodedValue1000 = B. encode value1000
103
+ encodedValue1000 = encode value1000
107
104
108
105
encodedValue10000 :: LBS. ByteString
109
- encodedValue10000 = B. encode value10000
106
+ encodedValue10000 = encode value10000
110
107
111
108
-------------------------------------------------------------------------------
112
109
-- Helpers
113
110
-------------------------------------------------------------------------------
114
111
115
- decodeHMB
116
- :: (B. FromJSONKey k , Eq k , Hashable k )
112
+ decodeHM
113
+ :: (FromJSON ( HM. HashMap k T. Text ) , Eq k , Hashable k )
117
114
=> Proxy k -> LBS. ByteString -> Maybe (HM. HashMap k T. Text )
118
- decodeHMB _ = B. decode
115
+ decodeHM _ = decode
119
116
120
- decodeHMA
121
- :: (A. FromJSON (HM. HashMap k T. Text ), Eq k , Hashable k )
122
- => Proxy k -> LBS. ByteString -> Maybe (HM. HashMap k T. Text )
123
- decodeHMA _ = A. decode
124
-
125
- decodeMapB
126
- :: (B. FromJSONKey k , Ord k )
127
- => Proxy k -> LBS. ByteString -> Maybe (M. Map k T. Text )
128
- decodeMapB _ = B. decode
129
-
130
- decodeMapA
131
- :: (A. FromJSON (M. Map k T. Text ), Ord k )
117
+ decodeMap
118
+ :: (FromJSON (M. Map k T. Text ), Ord k )
132
119
=> Proxy k -> LBS. ByteString -> Maybe (M. Map k T. Text )
133
- decodeMapA _ = A. decode
120
+ decodeMap _ = decode
134
121
135
122
proxyText :: Proxy T. Text
136
123
proxyText = Proxy
@@ -156,45 +143,41 @@ benchDecodeHM
156
143
-> LBS. ByteString
157
144
-> Benchmark
158
145
benchDecodeHM name val = bgroup name
159
- [ bench " Text" $ nf (decodeHMB proxyText) val
160
- , bench " Identity" $ nf (decodeHMB proxyT1) val
161
- , bench " Coerce" $ nf (decodeHMB proxyT2) val
162
- , bench " Parser" $ nf (decodeHMB proxyT3) val
163
- , bench " aeson-hackage" $ nf (decodeHMA proxyText) val
164
- , bench " Tagged Text" $ nf (decodeHMB $ proxyTagged proxyText) val
165
- , bench " Tagged Identity" $ nf (decodeHMB $ proxyTagged proxyT1) val
166
- , bench " Tagged Coerce" $ nf (decodeHMB $ proxyTagged proxyT2) val
167
- , bench " Tagged Parser" $ nf (decodeHMB $ proxyTagged proxyT3) val
146
+ [ bench " Text" $ nf (decodeHM proxyText) val
147
+ , bench " Identity" $ nf (decodeHM proxyT1) val
148
+ , bench " Coerce" $ nf (decodeHM proxyT2) val
149
+ , bench " Parser" $ nf (decodeHM proxyT3) val
150
+ , bench " Tagged Text" $ nf (decodeHM $ proxyTagged proxyText) val
151
+ , bench " Tagged Identity" $ nf (decodeHM $ proxyTagged proxyT1) val
152
+ , bench " Tagged Coerce" $ nf (decodeHM $ proxyTagged proxyT2) val
153
+ , bench " Tagged Parser" $ nf (decodeHM $ proxyTagged proxyT3) val
168
154
]
169
155
170
156
benchDecodeMap
171
157
:: String
172
158
-> LBS. ByteString
173
159
-> Benchmark
174
160
benchDecodeMap name val = bgroup name
175
- [ bench " Text" $ nf (decodeMapB proxyText) val
176
- , bench " Identity" $ nf (decodeMapB proxyT1) val
177
- , bench " Coerce" $ nf (decodeMapB proxyT2) val
178
- , bench " Parser" $ nf (decodeMapB proxyT3) val
179
- , bench " aeson-hackage" $ nf (decodeMapA proxyText) val
161
+ [ bench " Text" $ nf (decodeMap proxyText) val
162
+ , bench " Identity" $ nf (decodeMap proxyT1) val
163
+ , bench " Coerce" $ nf (decodeMap proxyT2) val
164
+ , bench " Parser" $ nf (decodeMap proxyT3) val
180
165
]
181
166
182
167
benchEncodeHM
183
168
:: String
184
169
-> HM. HashMap T. Text T. Text
185
170
-> Benchmark
186
171
benchEncodeHM name val = bgroup name
187
- [ bench " Text" $ nf B. encode val
188
- , bench " aeson-0.11" $ nf A. encode val
172
+ [ bench " Text" $ nf encode val
189
173
]
190
174
191
175
benchEncodeMap
192
176
:: String
193
177
-> HM. HashMap T. Text T. Text
194
178
-> Benchmark
195
179
benchEncodeMap name val = bgroup name
196
- [ bench " Text" $ nf B. encode val'
197
- , bench " aeson-0.11" $ nf A. encode val'
180
+ [ bench " Text" $ nf encode val'
198
181
]
199
182
where
200
183
val' :: M. Map T. Text T. Text
0 commit comments