From 5e395da12ef08ff5b69a0e436fe045c36e41dfd2 Mon Sep 17 00:00:00 2001 From: Sam T Date: Mon, 26 Aug 2013 21:42:27 +0400 Subject: + Add bench for generics. --- bench/Main.hs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'bench') diff --git a/bench/Main.hs b/bench/Main.hs index db9b47c..0822395 100644 --- a/bench/Main.hs +++ b/bench/Main.hs @@ -1,4 +1,5 @@ {-# LANGUAGE PackageImports #-} +{-# LANGUAGE DeriveGeneric #-} module Main (main) where import Control.DeepSeq @@ -10,6 +11,8 @@ import Data.List as L import Criterion.Main import System.Environment +import GHC.Generics + import "bencode" Data.BEncode as A import Data.AttoBencode as B import Data.AttoBencode.Parser as B @@ -31,6 +34,23 @@ instance NFData B.BValue where getRight :: Either String a -> a getRight = either error id +data List a = Cons a (List a) | Nil + deriving Generic + +instance BEncodable a => BEncodable (List a) + +instance NFData a => NFData (List a) where + rnf Nil = () + rnf (Cons x xs) = rnf (x, xs) + +replicate' :: Int -> a -> List a +replicate' c x + | c >= 0 = go c + | otherwise = Nil + where + go 0 = Nil + go n = Cons x $ go (pred n) + main :: IO () main = do (path : args) <- getArgs @@ -91,4 +111,10 @@ main = do nf (getRight . C.decoded . BL.toStrict . C.encoded :: [Int] -> [Int] ) d + + , let d = replicate' 10000 0 + in bench "list10000int/bencoding/encode>>decode/generic" $ + nf (getRight . C.decoded . BL.toStrict . C.encoded + :: List Int -> List Int) + d ] -- cgit v1.2.3