criterion-0.6.2.0: Robust, reliable performance measurement and analysis

Portability | GHC
Stability | experimental
Maintainer | bos@serpentine.com
Safe Haskell | Safe-Inferred

Criterion.Types

Description

Types for benchmarking.

The core class is `Benchmarkable`, which admits both pure functions and `IO` actions.

For a pure function of type `a -> b`, the benchmarking harness calls this function repeatedly, each time with a different `Int` argument, and reduces the result the function returns to weak head normal form. If you need the result reduced to normal form, that is your responsibility.

For an action of type `IO a`, the benchmarking harness calls the action repeatedly, but does not reduce the result.

Synopsis

- class Benchmarkable a where
  - run :: a -> Int -> IO ()
- data Benchmark where
  - Benchmark :: Benchmarkable b => String -> b -> Benchmark
  - BenchGroup :: String -> [Benchmark] -> Benchmark
  - BenchCompare :: [Benchmark] -> Benchmark
- data Pure
- whnf :: (a -> b) -> a -> Pure
- nf :: NFData b => (a -> b) -> a -> Pure
- nfIO :: NFData a => IO a -> IO ()
- whnfIO :: IO a -> IO ()
- bench :: Benchmarkable b => String -> b -> Benchmark
- bgroup :: String -> [Benchmark] -> Benchmark
- bcompare :: [Benchmark] -> Benchmark
- benchNames :: Benchmark -> [String]

# Documentation

class Benchmarkable a where Source

A benchmarkable function or action.

Methods

run Source

Arguments

:: a | The function or action to benchmark.
-> Int | The number of times to run or evaluate it.
-> IO () |

Run a function or action the specified number of times.

Instances

Benchmarkable Pure |
Benchmarkable (IO a) |

data Benchmark where Source

A benchmark may consist of either a single `Benchmarkable` item with a name, created with `bench`, or a (possibly nested) group of `Benchmark`s, created with `bgroup`.

Constructors

Benchmark :: Benchmarkable b => String -> b -> Benchmark |
BenchGroup :: String -> [Benchmark] -> Benchmark |
BenchCompare :: [Benchmark] -> Benchmark |

Instances

Show Benchmark |

data Pure Source

A container for a pure function to benchmark, and an argument to supply to it each time it is evaluated.

Instances

Benchmarkable Pure |

whnf :: (a -> b) -> a -> Pure Source

Apply an argument to a function, and evaluate the result to weak head normal form (WHNF).

nf :: NFData b => (a -> b) -> a -> Pure Source

Apply an argument to a function, and evaluate the result to head normal form (NF).

nfIO :: NFData a => IO a -> IO ()Source

Perform an action, then evaluate its result to head normal form. This is particularly useful for forcing a lazy IO action to be completely performed.

whnfIO :: IO a -> IO ()Source

Perform an action, then evaluate its result to weak head normal form (WHNF). This is useful for forcing an IO action whose result is an expression to be evaluated down to a more useful value.

bench Source

Arguments

:: Benchmarkable b |
=> String | A name to identify the benchmark.
-> b |
-> Benchmark |

Create a single benchmark.

bgroup Source

Arguments

:: String | A name to identify the group of benchmarks.
-> [Benchmark] | Benchmarks to group under this name.
-> Benchmark |

Group several benchmarks together under a common name.

bcompare :: [Benchmark] -> Benchmark Source

Compare benchmarks against a reference benchmark (The first `bench` in the given list).

The results of the comparisons are written to a CSV file specified using the `-r` command line flag. The CSV file uses the following format:

    Reference,Name,% faster than the reference

benchNames :: Benchmark -> [String]Source

Retrieve the names of all benchmarks. Grouped benchmarks are prefixed with the name of the group they're in.