BencheeDsl - ExUnit style and a livebook smart cell for benchee

Hi!

BencheeDsl provides a DSL for the great Benchee (micro) benchmarking tool.

With the DSL you can write benchmarks like:

defmodule Benchmark do
  use BencheeDsl.Benchmark

  config time: 3, pre_check: true, print: [configuration: false]

  inputs %{
    "Small" => Enum.to_list(1..1_000),
    "Medium" => Enum.to_list(1..10_000),
    "Bigger" => Enum.to_list(1..100_000)
  }

  defp map_fun(i), do: [i, i * i]

  job flat_map(input) do
    Enum.flat_map(input, &map_fun/1)
  end

  job map_flatten(input) do
    input |> Enum.map(&map_fun/1) |> List.flatten()
  end
end

The lib comes with two mix tasks. One to generate the bench directory and bench/benchee_helper.exs. The mix bench task will run the benchmarks found by bench/*_bench.exs.

BencheeDsl comes also with support for livebook and with the Benchee smart cell. See benchee_dsl.livemd.

The Benchee smart cell is my very first attempt at writing a smart cell.

Thanks for reading!

6 Likes

The smart cell renders now markdown when benchee_markdown is installed.

7 Likes

Thanks for working on this!

I was wondering how your Livebook integration differs from kino_benchee, and whether it might make sense for you to contribute any enhancements you’ve made to that project, if you have the time.

I was wondering how your Livebook integration differs from kino_benchee , and whether it might make sense for you to contribute any enhancements you’ve made to that project, if you have the time.

In benchee_dsl the integration is quite easy, just %Benchee.Suite{} |> Benchee.Formaters.Markdown.redner() |> Kino.Markdown.new(). kino_benchee implements defimpl Kino.Render, for: Benchee.Suite. So the implementation is cleaner and more general. kino_benchee uses also some new upcoming features of Livebook next version and renders some nice charts with kino_vega_lite. The package waits for on change in benchee and for the next Livebook version. I will remove the Livebook integration in benchee_dsl as soon as kino_benchee is available.

2 Likes