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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Test.Tasty.Bench (Benchmark, bench, bgroup, defaultMain, whnf)
import qualified Data.ByteString as BS
import qualified Data.Text as T
import qualified Alternative
import qualified Naive
import Data.Integer.Conversion
main :: IO ()
main = defaultMain
[ bgroup "text"
[ bgroup "naive" $ seriesT Naive.textToInteger
, bgroup "alt" $ seriesT Alternative.textToInteger
, bgroup "proper" $ seriesT textToInteger
]
, bgroup "bs"
[ bgroup "naive" $ seriesB Naive.byteStringToInteger
, bgroup "alt" $ seriesB Alternative.byteStringToInteger
, bgroup "proper" $ seriesB byteStringToInteger
]
, bgroup "string"
[ bgroup "naive" $ seriesL Naive.stringToInteger
, bgroup "alt" $ seriesL Alternative.stringToInteger
, bgroup "read" $ seriesL read
, bgroup "proper" $ seriesL stringToInteger
]
]
where
seriesT :: (T.Text -> Integer) -> [Benchmark]
seriesT f =
[ bench (show n) $ whnf f t
| e <- [6 .. 18 :: Int]
, let n = 2 ^ e
, let t = T.replicate n "9"
]
seriesB :: (BS.ByteString -> Integer) -> [Benchmark]
seriesB f =
[ bench (show n) $ whnf f t
| e <- [6 .. 18 :: Int]
, let n = 2 ^ e
, let t = BS.replicate n (48 + 9)
]
seriesL :: (String -> Integer) -> [Benchmark]
seriesL f =
[ bench (show n) $ whnf f t
| e <- [6 .. 18 :: Int]
, let n = 2 ^ e
, let t = replicate n '9'
]
|