@@ -0,0 +1,29 @@
1+module Typed.TH (benchmarks) where
2+
3+import Control.Applicative
4+import Criterion
5+import Data.Aeson hiding (Result)
6+import Data.ByteString.Builder as B
7+import Data.ByteString.Lazy as L
8+import Twitter.Generic
9+import Typed.Common
10+
11+encodeDirect :: Result -> L.ByteString
12+encodeDirect = B.toLazyByteString . fromEncoding . toEncoding
13+
14+encodeViaValue :: Result -> L.ByteString
15+encodeViaValue = encode
16+
17+benchmarks :: Benchmark
18+benchmarks =
19+ env ((,) <$> load "json-data/twitter100.json" <*> load "json-data/jp100.json") $ \ ~(twitter100, jp100) ->
20+ bgroup "th" [
21+ bgroup "direct" [
22+ bench "twitter100" $ nf encodeDirect twitter100
23+ , bench "jp100" $ nf encodeDirect jp100
24+ ]
25+ , bgroup "viaValue" [
26+ bench "twitter100" $ nf encodeViaValue twitter100
27+ , bench "jp100" $ nf encodeViaValue jp100
28+ ]
29+ ]