inoas / glychee

Glychee: Easy access to Elixir's benchee in Gleam
https://hexdocs.pm/glychee
Apache License 2.0
14 stars 0 forks source link

Remove gleam_stdlib dependency #1

Closed inoas closed 1 year ago

inoas commented 1 year ago

Uses: io.print, io.println, list.each, list.map

Uses some more in the example file, which could be removed as well, the example can live on as documentation.

Once these are removed, glychee can be used to benchmark gleam_stdlib functions.

inoas commented 1 year ago

Removed gleam_erlang and gleeunit deps already:

https://github.com/inoas/glychee/tree/remove-stdlib-dep

inoas commented 1 year ago

Closed in 0.2.0.

Now even in gleam_stdlib you can do:

gleam add glychee
gleam touch src/benchmark.gleam

paste:

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

run:

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