Skip to content

Instantly share code, notes, and snippets.

@basvandijk
Created November 3, 2011 13:05
Show Gist options
  • Save basvandijk/1336426 to your computer and use it in GitHub Desktop.
Save basvandijk/1336426 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DeriveDataTypeable, TemplateHaskell, TypeFamilies, EmptyDataDecls, TypeOperators #-}
module Main where
--------------------------------------------------------------------------------
import Criterion.Main
import Control.DeepSeq (NFData, rnf, deepseq)
import Data.Typeable (Typeable)
import Data.Data (Data)
import GHC.Generics
import Data.Aeson.Types
import Data.Aeson.TH (mkToJSON, mkParseJSON)
import qualified Data.Aeson.Generic as G (fromJSON, toJSON)
--------------------------------------------------------------------------------
data BigSum = F01 | F02 | F03 | F04 | F05
| F06 | F07 | F08 | F09 | F10
| F11 | F12 | F13 | F14 | F15
| F16 | F17 | F18 | F19 | F20
| F21 | F22 | F23 | F24 | F25
deriving (Show, Eq, Data, Typeable)
instance NFData BigSum
bigSum = F25
instance ToJSON BigSum
instance FromJSON BigSum
thBigSumToJSON :: BigSum -> Value
thBigSumToJSON = $(mkToJSON id ''BigSum)
thBigSumParseJSON :: Value -> Parser BigSum
thBigSumParseJSON = $(mkParseJSON id ''BigSum)
thBigSumFromJSON :: Value -> Result BigSum
thBigSumFromJSON = parse thBigSumParseJSON
--------------------------------------------------------------------------------
instance Generic BigSum where
type Rep BigSum = D1 D1BigSum
((((C1 C1_0BigSum U1
:+: (C1 C1_1BigSum U1 :+: C1 C1_2BigSum U1))
:+: (C1 C1_3BigSum U1
:+: (C1 C1_4BigSum U1 :+: C1 C1_5BigSum U1)))
:+: ((C1 C1_6BigSum U1
:+: (C1 C1_7BigSum U1 :+: C1 C1_8BigSum U1))
:+: (C1 C1_9BigSum U1
:+: (C1 C1_10BigSum U1 :+: C1 C1_11BigSum U1))))
:+: (((C1 C1_12BigSum U1
:+: (C1 C1_13BigSum U1 :+: C1 C1_14BigSum U1))
:+: (C1 C1_15BigSum U1
:+: (C1 C1_16BigSum U1 :+: C1 C1_17BigSum U1)))
:+: ((C1 C1_18BigSum U1
:+: (C1 C1_19BigSum U1 :+: C1 C1_20BigSum U1))
:+: ((C1 C1_21BigSum U1 :+: C1 C1_22BigSum U1)
:+: (C1 C1_23BigSum U1
:+: C1 C1_24BigSum U1)))))
from F01 = M1 (L1 (L1 (L1 (L1 (M1 U1)))))
from F02 = M1 (L1 (L1 (L1 (R1 (L1 (M1 U1))))))
from F03 = M1 (L1 (L1 (L1 (R1 (R1 (M1 U1))))))
from F04 = M1 (L1 (L1 (R1 (L1 (M1 U1)))))
from F05 = M1 (L1 (L1 (R1 (R1 (L1 (M1 U1))))))
from F06 = M1 (L1 (L1 (R1 (R1 (R1 (M1 U1))))))
from F07 = M1 (L1 (R1 (L1 (L1 (M1 U1)))))
from F08 = M1 (L1 (R1 (L1 (R1 (L1 (M1 U1))))))
from F09 = M1 (L1 (R1 (L1 (R1 (R1 (M1 U1))))))
from F10 = M1 (L1 (R1 (R1 (L1 (M1 U1)))))
from F11 = M1 (L1 (R1 (R1 (R1 (L1 (M1 U1))))))
from F12 = M1 (L1 (R1 (R1 (R1 (R1 (M1 U1))))))
from F13 = M1 (R1 (L1 (L1 (L1 (M1 U1)))))
from F14 = M1 (R1 (L1 (L1 (R1 (L1 (M1 U1))))))
from F15 = M1 (R1 (L1 (L1 (R1 (R1 (M1 U1))))))
from F16 = M1 (R1 (L1 (R1 (L1 (M1 U1)))))
from F17 = M1 (R1 (L1 (R1 (R1 (L1 (M1 U1))))))
from F18 = M1 (R1 (L1 (R1 (R1 (R1 (M1 U1))))))
from F19 = M1 (R1 (R1 (L1 (L1 (M1 U1)))))
from F20 = M1 (R1 (R1 (L1 (R1 (L1 (M1 U1))))))
from F21 = M1 (R1 (R1 (L1 (R1 (R1 (M1 U1))))))
from F22 = M1 (R1 (R1 (R1 (L1 (L1 (M1 U1))))))
from F23 = M1 (R1 (R1 (R1 (L1 (R1 (M1 U1))))))
from F24 = M1 (R1 (R1 (R1 (R1 (L1 (M1 U1))))))
from F25 = M1 (R1 (R1 (R1 (R1 (R1 (M1 U1))))))
{-# INLINE from #-}
to (M1 (L1 (L1 (L1 (L1 (M1 U1)))))) = F01
to (M1 (L1 (L1 (L1 (R1 (L1 (M1 U1))))))) = F02
to (M1 (L1 (L1 (L1 (R1 (R1 (M1 U1))))))) = F03
to (M1 (L1 (L1 (R1 (L1 (M1 U1)))))) = F04
to (M1 (L1 (L1 (R1 (R1 (L1 (M1 U1))))))) = F05
to (M1 (L1 (L1 (R1 (R1 (R1 (M1 U1))))))) = F06
to (M1 (L1 (R1 (L1 (L1 (M1 U1)))))) = F07
to (M1 (L1 (R1 (L1 (R1 (L1 (M1 U1))))))) = F08
to (M1 (L1 (R1 (L1 (R1 (R1 (M1 U1))))))) = F09
to (M1 (L1 (R1 (R1 (L1 (M1 U1)))))) = F10
to (M1 (L1 (R1 (R1 (R1 (L1 (M1 U1))))))) = F11
to (M1 (L1 (R1 (R1 (R1 (R1 (M1 U1))))))) = F12
to (M1 (R1 (L1 (L1 (L1 (M1 U1)))))) = F13
to (M1 (R1 (L1 (L1 (R1 (L1 (M1 U1))))))) = F14
to (M1 (R1 (L1 (L1 (R1 (R1 (M1 U1))))))) = F15
to (M1 (R1 (L1 (R1 (L1 (M1 U1)))))) = F16
to (M1 (R1 (L1 (R1 (R1 (L1 (M1 U1))))))) = F17
to (M1 (R1 (L1 (R1 (R1 (R1 (M1 U1))))))) = F18
to (M1 (R1 (R1 (L1 (L1 (M1 U1)))))) = F19
to (M1 (R1 (R1 (L1 (R1 (L1 (M1 U1))))))) = F20
to (M1 (R1 (R1 (L1 (R1 (R1 (M1 U1))))))) = F21
to (M1 (R1 (R1 (R1 (L1 (L1 (M1 U1))))))) = F22
to (M1 (R1 (R1 (R1 (L1 (R1 (M1 U1))))))) = F23
to (M1 (R1 (R1 (R1 (R1 (L1 (M1 U1))))))) = F24
to (M1 (R1 (R1 (R1 (R1 (R1 (M1 U1))))))) = F25
{-# INLINE to #-}
data D1BigSum
data C1_0BigSum
data C1_1BigSum
data C1_2BigSum
data C1_3BigSum
data C1_4BigSum
data C1_5BigSum
data C1_6BigSum
data C1_7BigSum
data C1_8BigSum
data C1_9BigSum
data C1_10BigSum
data C1_11BigSum
data C1_12BigSum
data C1_13BigSum
data C1_14BigSum
data C1_15BigSum
data C1_16BigSum
data C1_17BigSum
data C1_18BigSum
data C1_19BigSum
data C1_20BigSum
data C1_21BigSum
data C1_22BigSum
data C1_23BigSum
data C1_24BigSum
instance Datatype D1BigSum where
datatypeName _ = "BigSum"
moduleName _ = "Main"
instance Constructor C1_0BigSum where conName _ = "F01"
instance Constructor C1_1BigSum where conName _ = "F02"
instance Constructor C1_2BigSum where conName _ = "F03"
instance Constructor C1_3BigSum where conName _ = "F04"
instance Constructor C1_4BigSum where conName _ = "F05"
instance Constructor C1_5BigSum where conName _ = "F06"
instance Constructor C1_6BigSum where conName _ = "F07"
instance Constructor C1_7BigSum where conName _ = "F08"
instance Constructor C1_8BigSum where conName _ = "F09"
instance Constructor C1_9BigSum where conName _ = "F10"
instance Constructor C1_10BigSum where conName _ = "F11"
instance Constructor C1_11BigSum where conName _ = "F12"
instance Constructor C1_12BigSum where conName _ = "F13"
instance Constructor C1_13BigSum where conName _ = "F14"
instance Constructor C1_14BigSum where conName _ = "F15"
instance Constructor C1_15BigSum where conName _ = "F16"
instance Constructor C1_16BigSum where conName _ = "F17"
instance Constructor C1_17BigSum where conName _ = "F18"
instance Constructor C1_18BigSum where conName _ = "F19"
instance Constructor C1_19BigSum where conName _ = "F20"
instance Constructor C1_20BigSum where conName _ = "F21"
instance Constructor C1_21BigSum where conName _ = "F22"
instance Constructor C1_22BigSum where conName _ = "F23"
instance Constructor C1_23BigSum where conName _ = "F24"
instance Constructor C1_24BigSum where conName _ = "F25"
--------------------------------------------------------------------------------
type FJ a = Value -> Result a
main :: IO ()
main = defaultMain
[ let v = thBigSumToJSON bigSum
in bigSum `deepseq` v `deepseq`
bgroup "BigSum"
[ group "toJSON" (nf thBigSumToJSON bigSum)
(nf G.toJSON bigSum)
(nf toJSON bigSum)
, group "fromJSON" (nf (thBigSumFromJSON :: FJ BigSum) v)
(nf (G.fromJSON :: FJ BigSum) v)
(nf (fromJSON :: FJ BigSum) v)
]
]
group n th syb gen = bgroup n [ bench "th" th
, bench "syb" syb
, bench "generic" gen
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment