glychee/benchmark

Benchmark

Contain’s custom types and a runner function to process those.

Example

// In your application or library in src/benchmark.gleam:
import glychee/benchmark
import gleam/list
import gleam/int

pub fn main() {
  benchmark.run(
    [
      benchmark.Function(
        // swap the label for your function name's
        label: "list.sort()",
        callable:fn(test_data) {
         fn() {
           // swap for your function to benchmark
           list.sort(test_data, int.compare)
         }
       },
      ),
      // You can add another function here to compare against.
    ],
    [
      // Replace these with data expected by your function(s).
      benchmark.Data(
       label: "pre-sorted list",
       data: list.range(1, 100_000)
     ),
      benchmark.Data(
        label: "reversed list",
        data: list.range(1, 100_000)
        |> list.reverse,
      )
    ],
  )
}

Run via:

gleam clean && \
gleam build && \
erl -pa ./build/dev/erlang/*/ebin -noshell -eval 'gleam@@main:run(benchmark)'

Types

Data pairs arbitrary data to benchmark on with a label.

The label is used as part of the benchmark’s stdout output.

pub type Data(data) {
  Data(label: String, data: data)
}

Constructors

  • Data(label: String, data: data)

Function pairs a label with a function returning a callable.

The function requires some test_data.

The label is used as part of the benchmark’s stdout output.

pub type Function(test_data, any) {
  Function(label: String, callable: fn(test_data) -> fn() -> any)
}

Constructors

  • Function(label: String, callable: fn(test_data) -> fn() -> any)

Functions

pub fn run(function_list: List(Function(a, b)), data_list: List(
    Data(a),
  )) -> Nil

Takes a List of Function and List of Data and runs benchmarks for each Function combined with each Data grouped by Data first and Function second.

Utilized Benchee and its stdout’s output to print the function’s benchmark results for all data.

Search Document