module Test.SBench.Time.Series.Test (
runtimeSeries
, runtimeSeriesWith
, nfRuntimeSeries
, whnfRuntimeSeries
, scaleRt
) where
import Criterion.Main ( defaultMainWith, bgroup, bench, nf, whnf )
import Criterion.Config ( Config(..), defaultConfig )
import Data.Monoid ( Last(..) )
import System.FilePath ( (<.>), dropExtension )
import qualified Control.DeepSeq ( NFData, deepseq )
import Test.SBench.STerm ( Algorithm, DataGen, Seed, STerm (..), (<$>) )
import Test.SBench.Options ( EvalMod (..), Title )
import Test.SBench.File.FileOps ( criterion2series, series2sbench )
type BuildOptions = String
type ExeOptions = String
scaleRt :: Double -> [(Int, Double)] -> [(Int, Double)]
scaleRt f = map (\(x,y) -> (x,f*y))
defltCriterionFile = "temp" <.> "csv"
runtimeSeriesWith :: (Control.DeepSeq.NFData b, Show c, Real c) =>
Config
-> EvalMod
-> Maybe (BuildOptions, ExeOptions, FilePath, Title)
-> Algorithm (a -> b)
-> DataGen (c -> a)
-> [Seed c]
-> IO [(c, Double)]
runtimeSeriesWith cfg evalMod sbfile alg gen seeds = do
putStrLn "enter criterion benchmarking .."
t <- defaultMainWith cfg (return ()) benches
putStrLn $ "finished criterion benchmarking with " ++ show t
s <- criterion2series (map stTerm seeds) file
case sbfile of
Nothing -> return s
Just (b,e,f,t) -> series2sbench (b, e) (Just evalMod) alg gen t f s
>> return s
where
file = case cfgSummaryFile cfg of
Last (Just f) -> f
_ -> defltCriterionFile
benches = [ bgroup (dropExtension file) $ map (toBench gen) seeds ]
toBench gen seed = let inp = gen <$> seed in bench (stName inp) $ efun (stTerm alg) (stTerm inp)
efun = case evalMod of
NF -> nf
WHNF -> whnf
runtimeSeries :: (Control.DeepSeq.NFData b, Show c, Real c) =>
EvalMod
-> Maybe (BuildOptions, ExeOptions, FilePath, Title)
-> Algorithm (a -> b)
-> DataGen (c -> a)
-> [Seed c]
-> IO [(c, Double)]
runtimeSeries = runtimeSeriesWith defaultConfig {cfgSummaryFile = Last $ Just $ defltCriterionFile }
nfRuntimeSeries :: (Control.DeepSeq.NFData b, Show c, Real c) =>
Maybe (BuildOptions, ExeOptions, FilePath, Title)
-> Algorithm (a -> b)
-> DataGen (c -> a)
-> [Seed c]
-> IO [(c, Double)]
nfRuntimeSeries = runtimeSeries NF
whnfRuntimeSeries :: (Control.DeepSeq.NFData b, Show c, Real c) =>
Maybe (BuildOptions, ExeOptions, FilePath, Title)
-> Algorithm (a -> b)
-> DataGen (c -> a)
-> [Seed c]
-> IO [(c, Double)]
whnfRuntimeSeries = runtimeSeries WHNF