on master help sign in
Add TH support to typed benchmarks
commitc20a1ba1701411af921b3c0e53fc9c4c34886329 authorBryan O'Sullivan <bos@serpentine.com> dateTue 26 May 2015, 21:14 (11 years ago) parent1f031da
10 files changed+60−14
aeson.cabal+2 benchmarks/Typed.hs+2 benchmarks/Typed/Generic.hs+5−5 benchmarks/Typed/Manual.hs+5−5 benchmarks/Typed/TH.hs+29 benchmarks/aeson-benchmarks.cabal+1−4 benchmarks/Twitter.hs → examples/Twitter.hs+10 benchmarks/Twitter/Generic.hs → examples/Twitter/Generic.hs+2 benchmarks/Twitter/Manual.hs → examples/Twitter/Manual.hs+2 benchmarks/Twitter/TH.hs → examples/Twitter/TH.hs+2
aeson.cabal+2
@@ -64,10 +64,12 @@ extra-source-files:
6464 benchmarks/*.cabal
6565 benchmarks/*.hs
6666 benchmarks/*.py
67+ benchmarks/*/*.hs
6768 benchmarks/Makefile
6869 benchmarks/json-data/*.json
6970 changelog.md
7071 examples/*.hs
72+ examples/*/*.hs
7173
7274flag developer
7375 description: operate in developer mode
benchmarks/Typed.hs+2
@@ -3,9 +3,11 @@ module Main (main) where
33import Criterion.Main
44import qualified Typed.Generic as Generic
55import qualified Typed.Manual as Manual
6+import qualified Typed.TH as TH
67
78main :: IO ()
89main = defaultMain [
910 Generic.benchmarks
1011 , Manual.benchmarks
12+ , TH.benchmarks
1113 ]
benchmarks/Typed/Generic.hs+5−5
@@ -1,12 +1,12 @@
11module Typed.Generic (benchmarks) where
22
3−import Typed.Common
4−import Twitter.Generic
3+import Control.Applicative
4+import Criterion
55import Data.Aeson hiding (Result)
6−import Data.ByteString.Lazy as L
76import Data.ByteString.Builder as B
8−import Criterion
9−import Control.Applicative
7+import Data.ByteString.Lazy as L
8+import Twitter.TH
9+import Typed.Common
1010
1111encodeDirect :: Result -> L.ByteString
1212encodeDirect = B.toLazyByteString . fromEncoding . toEncoding
benchmarks/Typed/Manual.hs+5−5
@@ -1,12 +1,12 @@
11module Typed.Manual (benchmarks) where
22
3−import Twitter.Manual
4−import Typed.Common
3+import Control.Applicative
4+import Criterion
55import Data.Aeson hiding (Result)
6−import Data.ByteString.Lazy as L
76import Data.ByteString.Builder as B
8−import Criterion
9−import Control.Applicative
7+import Data.ByteString.Lazy as L
8+import Twitter.Manual
9+import Typed.Common
1010
1111encodeDirect :: Result -> L.ByteString
1212encodeDirect = 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
1919 Data.Aeson.Parser
2020 Data.Aeson.Types
2121 Data.Aeson.TH
22− Twitter.Generic
23− Twitter.Manual
24− Twitter.TH
2522
2623 other-modules:
2724 Data.Aeson.Encode.ByteString
@@ -31,7 +28,6 @@ library
3128 Data.Aeson.Types.Generic
3229 Data.Aeson.Types.Instances
3330 Data.Aeson.Types.Internal
34− Twitter
3531
3632 build-depends:
3733 attoparsec >= 0.13.0.0,
@@ -62,6 +58,7 @@ library
6258
6359executable aeson-benchmark-typed
6460 main-is: Typed.hs
61+ hs-source-dirs: ../examples .
6562 ghc-options: -Wall -O2 -rtsopts
6663 build-depends:
6764 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+
111{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
212
313module Twitter (
benchmarks/Twitter/Generic.hs → examples/Twitter/Generic.hsrenamed+2
@@ -1,3 +1,5 @@
1+-- Use GHC generics to automatically generate good instances.
2+
13{-# OPTIONS_GHC -fno-warn-orphans #-}
24
35module Twitter.Generic
benchmarks/Twitter/Manual.hs → examples/Twitter/Manual.hsrenamed+2
@@ -1,3 +1,5 @@
1+-- Manually write instances.
2+
13{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
24{-# OPTIONS_GHC -fno-warn-orphans #-}
35
benchmarks/Twitter/TH.hs → examples/Twitter/TH.hsrenamed+2
@@ -1,3 +1,5 @@
1+-- Use Template Haskell to generate good instances.
2+
13{-# LANGUAGE TemplateHaskell #-}
24{-# OPTIONS_GHC -fno-warn-orphans #-}
35