forked from mgsloan/rex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bench.hs
30 lines (21 loc) · 866 Bytes
/
Bench.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# LANGUAGE TemplateHaskell, QuasiQuotes, ViewPatterns #-}
module Main where
import Text.Regex.PCRE.Rex
import qualified Demo
import Criterion.Main
addEm :: Int -> [Double]
addEm n = map Demo.math $
zipWith (++)
(zipWith (++) (map show [1..n])
(concat $ repeat ["+", "/", "-", "*"]))
(map show [100..])
peanoize n = map (\i -> Demo.peano . (++"Z") . concat $ replicate i "S ") [0..n]
testPairs n = [Demo.parsePair $ "<" ++ replicate i ' ' ++ "a, pair>" | i <- [0..n]]
testDate n = [Demo.parseDate $ show i ++ ".10.20" | i <- [1900 .. 1900 + n]]
--NOTE: benchmark time includes test generation
main = defaultMain
[ bgroup "math" [ bench "10" $ nf addEm 10 ]
, bgroup "peano" [ bench "100" $ nf peanoize 100 ]
, bgroup "parsePair" [ bench "10" $ nf testPairs 10 ]
, bgroup "parseDate" [ bench "100" $ nf testDate 100 ]
]