on master help sign in
Add TH support to typed benchmarks
c20a1baBryan O'Sullivan
aeson.cabal+2
@@ -64,10 +64,12 @@ extra-source-files:
64 benchmarks/*.cabal
64 benchmarks/*.cabal
65 benchmarks/*.hs
65 benchmarks/*.hs
66 benchmarks/*.py
66 benchmarks/*.py
67+ benchmarks/*/*.hs
67 benchmarks/Makefile
68 benchmarks/Makefile
68 benchmarks/json-data/*.json
69 benchmarks/json-data/*.json
69 changelog.md
70 changelog.md
70 examples/*.hs
71 examples/*.hs
72+ examples/*/*.hs
71
73
72flag developer
74flag developer
73 description: operate in developer mode
75 description: operate in developer mode
benchmarks/Typed.hs+2
@@ -3,9 +3,11 @@ module Main (main) where
3import Criterion.Main
3import Criterion.Main
4import qualified Typed.Generic as Generic
4import qualified Typed.Generic as Generic
5import qualified Typed.Manual as Manual
5import qualified Typed.Manual as Manual
6+import qualified Typed.TH as TH
6
7
7main :: IO ()
8main :: IO ()
8main = defaultMain [
9main = defaultMain [
9 Generic.benchmarks
10 Generic.benchmarks
10 , Manual.benchmarks
11 , Manual.benchmarks
12+ , TH.benchmarks
11 ]
13 ]
benchmarks/Typed/Generic.hs+5−5
@@ -1,12 +1,12 @@
1module Typed.Generic (benchmarks) where
1module Typed.Generic (benchmarks) where
2
2
3−import Typed.Common
3+import Control.Applicative
4−import Twitter.Generic
4+import Criterion
5import Data.Aeson hiding (Result)
5import Data.Aeson hiding (Result)
6−import Data.ByteString.Lazy as L
7import Data.ByteString.Builder as B
6import Data.ByteString.Builder as B
8−import Criterion
7+import Data.ByteString.Lazy as L
9−import Control.Applicative
8+import Twitter.TH
9+import Typed.Common
10
10
11encodeDirect :: Result -> L.ByteString
11encodeDirect :: Result -> L.ByteString
12encodeDirect = B.toLazyByteString . fromEncoding . toEncoding
12encodeDirect = B.toLazyByteString . fromEncoding . toEncoding
benchmarks/Typed/Manual.hs+5−5
@@ -1,12 +1,12 @@
1module Typed.Manual (benchmarks) where
1module Typed.Manual (benchmarks) where
2
2
3−import Twitter.Manual
3+import Control.Applicative
4−import Typed.Common
4+import Criterion
5import Data.Aeson hiding (Result)
5import Data.Aeson hiding (Result)
6−import Data.ByteString.Lazy as L
7import Data.ByteString.Builder as B
6import Data.ByteString.Builder as B
8−import Criterion
7+import Data.ByteString.Lazy as L
9−import Control.Applicative
8+import Twitter.Manual
9+import Typed.Common
10
10
11encodeDirect :: Result -> L.ByteString
11encodeDirect :: Result -> L.ByteString
12encodeDirect = B.toLazyByteString . fromEncoding . toEncoding
12encodeDirect = B.toLazyByteString . fromEncoding . toEncoding
benchmarks/Typed/TH.hsnew file+29
@@ -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+ ]
benchmarks/aeson-benchmarks.cabal+1−4
@@ -19,9 +19,6 @@ library
19 Data.Aeson.Parser
19 Data.Aeson.Parser
20 Data.Aeson.Types
20 Data.Aeson.Types
21 Data.Aeson.TH
21 Data.Aeson.TH
22− Twitter.Generic
23− Twitter.Manual
24− Twitter.TH
25
22
26 other-modules:
23 other-modules:
27 Data.Aeson.Encode.ByteString
24 Data.Aeson.Encode.ByteString
@@ -31,7 +28,6 @@ library
31 Data.Aeson.Types.Generic
28 Data.Aeson.Types.Generic
32 Data.Aeson.Types.Instances
29 Data.Aeson.Types.Instances
33 Data.Aeson.Types.Internal
30 Data.Aeson.Types.Internal
34− Twitter
35
31
36 build-depends:
32 build-depends:
37 attoparsec >= 0.13.0.0,
33 attoparsec >= 0.13.0.0,
@@ -62,6 +58,7 @@ library
62
58
63executable aeson-benchmark-typed
59executable aeson-benchmark-typed
64 main-is: Typed.hs
60 main-is: Typed.hs
61+ hs-source-dirs: ../examples .
65 ghc-options: -Wall -O2 -rtsopts
62 ghc-options: -Wall -O2 -rtsopts
66 build-depends:
63 build-depends:
67 aeson-benchmarks,
64 aeson-benchmarks,
benchmarks/Twitter.hs → examples/Twitter.hsrenamed+10
@@ -1,3 +1,13 @@
1+-- These types follow the format of Twitter search results, as can be
2+-- found in the benchmarks/json-data directory.
3+--
4+-- For uses of these types, see the Twitter subdirectory.
5+--
6+-- There is one deviation for the sake of convenience: the Geo field
7+-- named "type_" is really named "type" in Twitter's real feed. I
8+-- renamed "type" to "type_" in the *.json files, to avoid overlap
9+-- with a Haskell reserved keyword.
10+
1{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
11{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
2
12
3module Twitter (
13module Twitter (
benchmarks/Twitter/Generic.hs → examples/Twitter/Generic.hsrenamed+2
@@ -1,3 +1,5 @@
1+-- Use GHC generics to automatically generate good instances.
2+
1{-# OPTIONS_GHC -fno-warn-orphans #-}
3{-# OPTIONS_GHC -fno-warn-orphans #-}
2
4
3module Twitter.Generic
5module Twitter.Generic
benchmarks/Twitter/Manual.hs → examples/Twitter/Manual.hsrenamed+2
@@ -1,3 +1,5 @@
1+-- Manually write instances.
2+
1{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
3{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
4{-# OPTIONS_GHC -fno-warn-orphans #-}
3
5
benchmarks/Twitter/TH.hs → examples/Twitter/TH.hsrenamed+2
@@ -1,3 +1,5 @@
1+-- Use Template Haskell to generate good instances.
2+
1{-# LANGUAGE TemplateHaskell #-}
3{-# LANGUAGE TemplateHaskell #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
4{-# OPTIONS_GHC -fno-warn-orphans #-}
3
5