Glychee

Package Version Hex Docs

A simple gleam benchmark runner which wraps Benchee.

Named after Gleam, Benchee and their fruity offspring, Lychee:

photo of a Lychee

Quick start

Notice: Requires at least gleam 0.24 (or gleam 0.0.0-nightly-221019 or later).

Also requires Elixir and hex be installed. You might be required to run mix local.hex after installing Elixir.

  1. Add glychee to your project: gleam add glychee.
  2. Create a a custom benchmarking module that contains a main-function. See glychee_example_benchmark_module.gleam as an example. In that module you will define which Functions to benchmark with one or many Data.
  3. Run the benchmark. bin/glychee_example_benchmark_call.sh in this library’s source shows an example on how do do it:

Example

If you do not have a Gleam project yet, create it with:

gleam new foobar
cd foobar

In your project create a file named src/benchmark.gleam with following source code:

if erlang {
  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,
        ),
      ],
    )
  }
}

Then run in your terminal via:

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

Now you can alter the functions and data specified in above’s example to whichever function of your application or library you want to benchmark.

Note that you can benchmark multiple functions with different data sets in one go.

Installation

If available on Hex this package can be added to your Gleam project:

gleam add glychee

Glychee’s documentation can be found at https://hexdocs.pm/glychee.

License

Apache 2.0

Search Document