MyNixOS website logo
Description

Simple and lightweight benchmarking utilities.

Simple benchmarking utilities with API subset of criterion (and also a subset of gauge and tasty-bench).

The goal of this package is to provide simple and lightweight benchmark utilities with less amount of codes and dependency packages. For robust and feature-rich benchmarking utility, use the other packages mentioned above.

Miniterion

ci codecov Hackage Stackage LTS Stackage nightly

Summary

Miniterion is a lightweight Haskell cabal package containing utilities for writing benchmark codes. The package has an API subset of criterion package, so switching to other benchmarking packages (criterion, gauge, and tasty-bench) should be easily done.

As in criterion, the executable built with the defaultMain supports selecting the running benchmarks with prefix match, case insensitive prefix match, substring match, or glob pattern match via the command line option. Invoke the benchmark executable with --help option to see other available options.

Motivation

The goal of the miniterion package is to have a reasonably useful and lightweight benchmarking utility with a small amount of maintenance effort. For robust and feature-rich benchmarking utility, use the other packages mentioned above.

The miniterion package is designed to have a small number of package dependencies. At the time of writing, the dependency packages are only two: base and deepseq. The miniterion package does not have rich features, but compared to other benchmarking packages, the package and benchmark executable should compile faster, and the resulting benchmark executable should be smaller.

Example

The following shows a simple benchmark with a naive Fibonacci function.

In cabal configuration:

benchmark fibo
    default-language: Haskell2010
    type:             exitcode-stdio-1.0
    hs-source-dirs:   bench
    main-is:          Main.hs
    build-depends:    base
                    , miniterion 

And in file bench/Main.hs:

module Main where

import Miniterion

fib :: Integer -> Integer
fib m | m < 0 = error "negative!"
      | otherwise = go m
  where
    go 0 = 0
    go 1 = 1
    go n = go (n-1) + go (n-2)

main :: IO ()
main = defaultMain [
  bgroup "fib" [ bench "1" $ whnf fib 1
               , bench "5" $ whnf fib 5
               , bench "9" $ whnf fib 9
               , bench "11" $ whnf fib 11
               ]
  ]

then compile and run the benchmark with cabal bench:

$ cabal bench
Build profile: -w ghc-9.6.2 -O1
In order, the following will be built (use -v for more details):
 - miniterion-0.1.0.0 (bench:fibo) (first run)
Preprocessing benchmark 'fibo' for miniterion-0.1.0.0..
Building benchmark 'fibo' for miniterion-0.1.0.0..
Running 1 benchmarks...
Benchmark fibo: RUNNING...
benchmarking fib/1
mean                 13.58 ns
std dev              686.0 ps

benchmarking fib/5
mean                 216.6 ns
std dev              15.78 ns

benchmarking fib/9
mean                 1.586 μs
std dev              89.60 ns

benchmarking fib/11
mean                 4.175 μs
std dev              92.17 ns

Benchmark fibo: FINISH

Run:

$ cabal run -- fibo --help

to see the help message.

Metadata

Version

0.1.1.1

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows