A simple Gleam benchmark runner which wraps Benchee for the heavy lifting.
Named after Gleam, Benchee and their fruity Lychee offspring:
mix local.hex
after installing Elixir.gleam add glychee --dev
.my_benchmark
that
contains a main
-function. In that module you will define which Function
s
to benchmark with one or many Data
.Run the benchmark:
gleam clean && \
gleam build && \
gleam run -m my_benchmark
If you do not have a Gleam project yet, create it with:
gleam new foobar
cd foobar
To add and run a demo of Glychee:
gleam add glychee --dev
In your project create a file named src/my_benchmark.gleam
with following source code:
import gleam/int
import gleam/list
import glychee/benchmark
import glychee/configuration
pub fn main() {
// Configuration is optional
configuration.initialize()
configuration.set_pair(configuration.Warmup, 2)
configuration.set_pair(configuration.Parallel, 2)
// Run the benchmarks
benchmark.run(
[
benchmark.Function(label: "list.sort()", callable: 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 && \
gleam run -m my_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.
Glychee's documentation can be found at https://hexdocs.pm/glychee.