criterion-plus-0.1.3: Enhancement of the "criterion" benchmarking library

Safe HaskellNone
LanguageHaskell2010

CriterionPlus

Contents

Description

Using this library you can create executables with benchmarks. It automatically implants a command-line options parser and info generator.

Here is an example of how this library is supposed to be used:

import CriterionPlus
import qualified SomeMySQLLib as MySQL
import qualified SomePostgreSQLLib as PostgreSQL

main = 
  benchmark $ do
    standoff "Inserting rows" $ do
      subject "MySQL" $ do
        -- Exclude the "setup" phase from measurement:
        pause
        connection <- liftIO $ MySQL.openConnection
        -- Measure what we want:
        continue
        liftIO $ MySQL.insertAThousandRows connection
        -- Exclude the "teardown" phase from measurement:
        pause
        liftIO $ MySQL.closeConnection connection
      subject "PostgreSQL" $ do
        -- This is how we can exclude the "setup" phase from monad transformers:
        pause
        PostgreSQL.runSession $ do
          lift $ continue
          PostgreSQL.insertAThousandRows
          -- Exclude "teardown":
          lift $ pause
    -- Each standoff generates an independent report file:
    standoff "Querying" $ do
      subject "MySQL" $ error "So on..."
      subject "PostgreSQL" $ error "So on..."

Synopsis

IO

benchmark :: Benchmark () -> IO () Source

Parse the command line options and run the benchmark.

Benchmark

data Benchmark a Source

A root of the "criterion-plus" monad stack.

Use this monad to declare standoffs. You can also lift a shared initialization into it using liftIO.

standoff :: Name -> Standoff () -> Benchmark () Source

Declare a named comparison of multiple subjects. This will generate a separate report file.

Standoff

data Standoff a Source

A monad for declaration of independent comparison, which will produce a dedicated report file.

Use this monad to group and declare subjects. You can also lift a shared initialization into it using liftIO.

group :: Name -> Standoff () -> Standoff () Source

Put the wrapped computations into a named group. Can be nested.

subject :: Name -> Subject a -> Standoff () Source

Execute a named subject.

Subject

data Subject a Source

A monad, which wraps the benchmarking subject and controls its measurement.

continue :: Subject () Source

Continue the timer.

By default it is already running, so if you need to eclude something from the beginning of the subject use pause. E.g.:

subject "MySQL" $ do
  pause
  connection <- liftIO $ openConnection
  continue
  liftIO $ workWithConnection connection
  pause
  liftIO $ closeConnection connection

pause :: Subject () Source

Pause the timer.

Evaluation

whnf :: MonadIO m => (a -> b) -> a -> m () Source

An adaptation of Criterion.Types.whnf.

nf :: (MonadIO m, NFData b) => (a -> b) -> a -> m () Source

An adaptation of Criterion.Types.nf.

nfIO :: (MonadIO m, NFData a) => IO a -> m () Source

An adaptation of Criterion.Types.nfIO.

whnfIO :: MonadIO m => IO a -> m () Source

An adaptation of Criterion.Types.whnfIO.

Shared Types