summaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-08-26 21:42:27 +0400
committerSam T <pxqr.sta@gmail.com>2013-08-26 21:42:27 +0400
commit5e395da12ef08ff5b69a0e436fe045c36e41dfd2 (patch)
treeab3b001fa221dcf766370c151590d790c7327a32 /bench
parent2dd7c644253beb50fd8a2256bba5bff7e32c0978 (diff)
+ Add bench for generics.
Diffstat (limited to 'bench')
-rw-r--r--bench/Main.hs26
1 files changed, 26 insertions, 0 deletions
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 @@
1{-# LANGUAGE PackageImports #-} 1{-# LANGUAGE PackageImports #-}
2{-# LANGUAGE DeriveGeneric #-}
2module Main (main) where 3module Main (main) where
3 4
4import Control.DeepSeq 5import Control.DeepSeq
@@ -10,6 +11,8 @@ import Data.List as L
10import Criterion.Main 11import Criterion.Main
11import System.Environment 12import System.Environment
12 13
14import GHC.Generics
15
13import "bencode" Data.BEncode as A 16import "bencode" Data.BEncode as A
14import Data.AttoBencode as B 17import Data.AttoBencode as B
15import Data.AttoBencode.Parser as B 18import Data.AttoBencode.Parser as B
@@ -31,6 +34,23 @@ instance NFData B.BValue where
31getRight :: Either String a -> a 34getRight :: Either String a -> a
32getRight = either error id 35getRight = either error id
33 36
37data List a = Cons a (List a) | Nil
38 deriving Generic
39
40instance BEncodable a => BEncodable (List a)
41
42instance NFData a => NFData (List a) where
43 rnf Nil = ()
44 rnf (Cons x xs) = rnf (x, xs)
45
46replicate' :: Int -> a -> List a
47replicate' c x
48 | c >= 0 = go c
49 | otherwise = Nil
50 where
51 go 0 = Nil
52 go n = Cons x $ go (pred n)
53
34main :: IO () 54main :: IO ()
35main = do 55main = do
36 (path : args) <- getArgs 56 (path : args) <- getArgs
@@ -91,4 +111,10 @@ main = do
91 nf (getRight . C.decoded . BL.toStrict . C.encoded 111 nf (getRight . C.decoded . BL.toStrict . C.encoded
92 :: [Int] -> [Int] ) 112 :: [Int] -> [Int] )
93 d 113 d
114
115 , let d = replicate' 10000 0
116 in bench "list10000int/bencoding/encode>>decode/generic" $
117 nf (getRight . C.decoded . BL.toStrict . C.encoded
118 :: List Int -> List Int)
119 d
94 ] 120 ]