The PonyBench package provides a microbenchmarking framework. It is designed to easily benchmark synchronous and asynchronous operations.

Example program

The following is a complete program with multiple trivial benchmarks followed by their output.

use "ponybench"
use "promises"

actor Main
  new create(env: Env) =>
    let bench = PonyBench(env)

    // benchmark Fib with different inputs
    bench[USize]("fib 5", {() => Fib(5) })
    bench[USize]("fib 10", {() => Fib(10) })
    bench[USize]("fib 20", {() => Fib(20) })
    bench[USize]("fib 40", {() => Fib(40) })

    // show what happens when a benchmark fails
    bench[String]("fail", {(): String ? => error })

    // async benchmark
    bench.async[USize]("async", {() => Promise[USize] .> apply(0) })

    // async benchmark timeout
    bench.async[USize]("timeout", {() => Promise[USize] }, 1_000_000)

    // benchmarks with set ops
    bench[USize]("add", {() => 1 + 2 }, 10_000_000)
    bench[USize]("sub", {() => 2 - 1 }, 10_000_000)

primitive Fib
  fun apply(n: USize): USize =>
    if n < 2 then
      n
    else
      apply(n - 1) + apply(n - 2)
    end

Output:

fib 5       50000000            33 ns/op
fib 10       5000000           371 ns/op
fib 20         30000         45310 ns/op
fib 40             2     684868666 ns/op
**** FAILED Benchmark: fail
async         200000         26512 ns/op
**** FAILED Benchmark: timeout (timeout)
add         10000000             2 ns/op
sub         10000000             2 ns/op

Public Types

Private Types