-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
70 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//// Contains helper functions copied from Gleam's stlib, | ||
//// so that there are no deps on Glychee. | ||
//// | ||
|
||
/// Replaces stdlib's `list.each`. | ||
/// | ||
pub fn gleam_list_each(list: List(a), f: fn(a) -> b) -> Nil { | ||
case list { | ||
[] -> Nil | ||
[x, ..xs] -> { | ||
f(x) | ||
gleam_list_each(xs, f) | ||
} | ||
} | ||
} | ||
|
||
/// Replaces stdlib's `io.println` | ||
/// | ||
@external(erlang, "io", "put_chars") | ||
pub fn gleam_io_println(text text: String) -> Nil | ||
|
||
/// Replaces stdlib's `list.map` | ||
/// | ||
pub fn gleam_list_map( | ||
list list: List(a), | ||
callable callable: fn(a) -> b, | ||
) -> List(b) { | ||
do_erlang_lists_map(callable, list) | ||
} | ||
|
||
@external(erlang, "lists", "map") | ||
fn do_erlang_lists_map( | ||
callable callable: fn(a) -> b, | ||
list list: List(a), | ||
) -> List(b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
defmodule GlycheeBenchee do | ||
@moduledoc """ | ||
Allows running of Benchee from Gleam | ||
Allows running of Benchee from Gleam. | ||
""" | ||
|
||
@doc """ | ||
Runs Benchee with some standard settings. | ||
Takes a list of function tuples, for example: | ||
Takes a list of function tuples. | ||
list_of_function_tuples [ | ||
{"flat_map", fn -> Enum.flat_map(test_data, fn i -> [i, i * i]) end} | ||
] | ||
""" | ||
def run(list_of_function_tuples) do | ||
map_of_function_tuples = list_of_function_tuples |> Enum.into(%{}) | ||
## Example | ||
Benchee.run( | ||
map_of_function_tuples, | ||
warmup: 4, | ||
time: 8, | ||
memory_time: 4, | ||
reduction_time: 4 | ||
) | ||
end | ||
```elixir | ||
list_of_function_tuples = [ | ||
{"flat_map", fn -> Enum.flat_map(test_data, fn i -> [i, i * i]) end} | ||
] | ||
``` | ||
""" | ||
@spec run(list({String.t(), function()})) :: Benchee.Suite.t() | ||
def run(list_of_function_tuples), | ||
do: | ||
list_of_function_tuples | ||
|> Enum.into(%{}) | ||
|> Benchee.run(warmup: 4, time: 8, memory_time: 4, reduction_time: 4) | ||
end |