glychee/benchmark

Benchmark

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

Example

// In src/benchmark.gleam
import glychee/benchmark
import gleam/list
import gleam/int

pub fn main() {
	benchmark.run(
		[
			benchmark.Function(
				label: "list.sort()",
				fun: fn(test_data) {
         fn() {
           list.sort(test_data, int.compare)
         }
       },
			),
		],
		[
			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, such as a List(Int) 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, fun: fn(test_data) -> any)
}

Constructors

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

Functions

pub fn run(function_sets: List(Function(a, b)), data_sets: 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’s stdout output for the function benchmarking.

Search Document