Safe Haskell | None |
---|---|
Language | Haskell2010 |
Library to comparatively benchmark pure functions, impure functions and shell commands with lazy precision.
Synopsis
- defaultMain :: [Benchmark] -> IO ()
- bench :: NFData b => String -> (a -> b) -> a -> Benchmark
- benchIO :: String -> IO a -> Benchmark
- benchShell :: String -> String -> Benchmark
- defaultMainWith :: Config -> [Benchmark] -> IO ()
- defaultConfig :: Config
- data Config = Config {
- hideBar :: Bool
- sameLine :: Bool
- hideDetails :: Bool
- printOnce :: Bool
- sortByMean :: Bool
- simple :: Bool
- confidence :: Double
- timeout :: Maybe Double
- relativeError :: Maybe Double
- isEqualTo :: Benchmark -> Benchmark -> IO Bool
- isFasterThan :: Benchmark -> Benchmark -> IO Bool
- standardDeviation :: Analysis -> Double
- standardError :: Analysis -> Double
- variance :: Analysis -> Rational
- step :: Benchmark -> IO Benchmark
- data Benchmark = Benchmark {}
- data Analysis = Analysis {}
Benchmark
defaultMain :: [Benchmark] -> IO () Source #
Main function for running a list of benchmarks. It also allows to specify options via commandline.
defaultMain [bench "not True" not True, bench "id True" id True]
bench :: NFData b => String -> (a -> b) -> a -> Benchmark Source #
Construct a benchmark of a name, a pure function and an argument.
bench "reverse abc" reverse "abc"
benchIO :: String -> IO a -> Benchmark Source #
Construct a benchmark of a name and an impure function.
benchIO "ioref" (newIORef () >>= readIORef)
benchShell :: String -> String -> Benchmark Source #
Construct a benchmark of a name and a shell command.
benchShell "sleep is slow" "sleep 0"
Configuration
defaultMainWith :: Config -> [Benchmark] -> IO () Source #
Configurable main function for running a list of benchmarks.
defaultMainWith defaultConfig {hideBar = True} [bench "id ()" id ()]
defaultConfig :: Config Source #
Default configuration. Use this combined with record updates to ensure compatibility with future releases.
Options wich can be specified on the command line or with defaultMainWith.
Config | |
|
Testing
isEqualTo :: Benchmark -> Benchmark -> IO Bool Source #
Determine whether two benchmarks have got the same performance. It runs each benchmark until their confidence intervals don't overlap - in which case False is returned - or are no bigger than 1% of the mean - in which case True is returned.
This function is meant to be used in test suites as infix function.
benchShell "echo" "echo" `isEqualTo` benchShell "sleep 0" "sleep 0"
isFasterThan :: Benchmark -> Benchmark -> IO Bool Source #
Determine whether a benchmark is faster than another. It runs each benchmark until their confidence intervals don't overlap or are no bigger than 1% of the mean. If the confidence intervals don't overlap and the mean of the first is lower True will be returned. Otherwise False.
This function is meant to be used in test suites as infix function.
benchShell "echo" "echo" `isFasterThan` benchShell "sleep 0" "sleep 0"
Analysis
standardDeviation :: Analysis -> Double Source #
Calculate the standard deviation of an Analysis.
standardError :: Analysis -> Double Source #
Calculate the standard error of an Analysis.
step :: Benchmark -> IO Benchmark Source #
Run the benchmark once and update its analysis. For functions with very low runtimes multiple runs will be executed.
Name, current analysis and function of a benchmark.