module Criterion.Config
(
Config(..)
, PlotOutput(..)
, Plot(..)
, PrintExit(..)
, Verbosity(..)
, defaultConfig
, fromLJ
, ljust
) where
import Criterion.MultiMap (MultiMap)
import Data.Data (Data)
import Data.Function (on)
import Data.Monoid (Monoid(..), Last(..))
import Data.Typeable (Typeable)
data Verbosity = Quiet
| Normal
| Verbose
deriving (Eq, Ord, Bounded, Enum, Read, Show, Typeable)
data PrintExit = Nada
| List
| Version
| Help
deriving (Eq, Ord, Bounded, Enum, Read, Show, Typeable, Data)
instance Monoid PrintExit where
mempty = Nada
mappend = max
data PlotOutput = CSV
| PDF Int Int
| PNG Int Int
| SVG Int Int
| Window Int Int
deriving (Eq, Ord, Read, Show, Typeable, Data)
data Plot = KernelDensity
| Timing
deriving (Eq, Ord, Read, Show, Typeable, Data)
data Config = Config {
cfgBanner :: Last String
, cfgConfInterval :: Last Double
, cfgPerformGC :: Last Bool
, cfgPlot :: MultiMap Plot PlotOutput
, cfgPlotSameAxis :: Last Bool
, cfgPrintExit :: PrintExit
, cfgResamples :: Last Int
, cfgSamples :: Last Int
, cfgSummaryFile :: Last FilePath
, cfgVerbosity :: Last Verbosity
} deriving (Eq, Read, Show, Typeable)
instance Monoid Config where
mempty = emptyConfig
mappend = appendConfig
defaultConfig :: Config
defaultConfig = Config {
cfgBanner = ljust "I don't know what version I am."
, cfgConfInterval = ljust 0.95
, cfgPerformGC = ljust False
, cfgPlot = mempty
, cfgPlotSameAxis = ljust False
, cfgPrintExit = Nada
, cfgResamples = ljust (100 * 1000)
, cfgSamples = ljust 100
, cfgSummaryFile = mempty
, cfgVerbosity = ljust Normal
}
ljust :: a -> Last a
ljust = Last . Just
fromLJ :: (Config -> Last a)
-> Config
-> a
fromLJ f cfg = case f cfg of
Last Nothing -> fromLJ f defaultConfig
Last (Just a) -> a
emptyConfig :: Config
emptyConfig = Config {
cfgBanner = mempty
, cfgConfInterval = mempty
, cfgPerformGC = mempty
, cfgPlot = mempty
, cfgPlotSameAxis = mempty
, cfgPrintExit = mempty
, cfgResamples = mempty
, cfgSamples = mempty
, cfgSummaryFile = mempty
, cfgVerbosity = mempty
}
appendConfig :: Config -> Config -> Config
appendConfig a b =
Config {
cfgBanner = app cfgBanner a b
, cfgConfInterval = app cfgConfInterval a b
, cfgPerformGC = app cfgPerformGC a b
, cfgPlot = app cfgPlot a b
, cfgPlotSameAxis = app cfgPlotSameAxis a b
, cfgPrintExit = app cfgPrintExit a b
, cfgSamples = app cfgSamples a b
, cfgSummaryFile = app cfgSummaryFile a b
, cfgResamples = app cfgResamples a b
, cfgVerbosity = app cfgVerbosity a b
}
where app f = mappend `on` f