|
1 | 1 | //// Contains custom types `Function` and `Data` and a runner function to run
|
2 | 2 | //// a list of these benchmark functions against a list of benchmark data.
|
| 3 | +//// |
| 4 | + |
| 5 | +import glychee/helpers as h |
3 | 6 |
|
4 | 7 | /// Function pairs a `label` with a function returning a callable.
|
5 | 8 | ///
|
@@ -34,58 +37,25 @@ pub fn run(
|
34 | 37 | function_list: List(Function(test_data, any)),
|
35 | 38 | data_list: List(Data(test_data)),
|
36 | 39 | ) -> Nil {
|
37 |
| - gleam_stdlib_each( |
38 |
| - data_list, |
39 |
| - fn(data) { |
40 |
| - erlang_io_put_chars("\n\n") |
41 |
| - erlang_io_put_chars(separator_line <> "\n") |
42 |
| - erlang_io_put_chars("==== data set: " <> data.label) |
43 |
| - erlang_io_put_chars("\n") |
44 |
| - erlang_io_put_chars(separator_line <> "\n") |
45 |
| - erlang_io_put_chars("\n") |
46 |
| - |
47 |
| - function_list |
48 |
| - |> erlang_lists_map( |
49 |
| - fn(function: Function(test_data, any)) { |
50 |
| - #(function.label, function.callable(data.data)) |
51 |
| - }, |
52 |
| - _, |
53 |
| - ) |
54 |
| - |> benchee_wrapper_run |
55 |
| - }, |
56 |
| - ) |
57 |
| -} |
58 |
| - |
59 |
| -/// Copy of stdlib's implementation. |
60 |
| -/// Copied here, so that there are no deps on Glychee. |
61 |
| -/// |
62 |
| -fn gleam_stdlib_each(list: List(a), f: fn(a) -> b) -> Nil { |
63 |
| - case list { |
64 |
| - [] -> Nil |
65 |
| - [x, ..xs] -> { |
66 |
| - f(x) |
67 |
| - gleam_stdlib_each(xs, f) |
68 |
| - } |
69 |
| - } |
| 40 | + h.gleam_list_each(data_list, fn(data) { |
| 41 | + h.gleam_io_println("\n\n") |
| 42 | + h.gleam_io_println(separator_line <> "\n") |
| 43 | + h.gleam_io_println("==== data set: " <> data.label) |
| 44 | + h.gleam_io_println("\n") |
| 45 | + h.gleam_io_println(separator_line <> "\n") |
| 46 | + h.gleam_io_println("\n") |
| 47 | + |
| 48 | + function_list |
| 49 | + |> h.gleam_list_map(fn(function: Function(test_data, any)) { |
| 50 | + #(function.label, function.callable(data.data)) |
| 51 | + }) |
| 52 | + |> benchee_wrapper_run |
| 53 | + }) |
70 | 54 | }
|
71 | 55 |
|
72 |
| -/// Replaces stdlib's io.println |
73 |
| -/// so that there are no deps on Glychee. |
74 |
| -/// |
75 |
| -@external(erlang, "io", "put_chars") |
76 |
| -fn erlang_io_put_chars(text text: String) -> Nil |
77 |
| - |
78 |
| -/// Replaces stdlib's list.map |
79 |
| -/// so that there are no deps on Glychee. |
80 |
| -/// |
81 |
| -@external(erlang, "lists", "map") |
82 |
| -fn erlang_lists_map(callable callable: fn(a) -> b, list list: List(a)) -> List( |
83 |
| - b, |
84 |
| -) |
85 |
| - |
86 | 56 | /// Wrapper for Elixir's Benchee
|
87 | 57 | ///
|
88 | 58 | @external(erlang, "Elixir.GlycheeBenchee", "run")
|
89 |
| -fn benchee_wrapper_run(list_of_function_tuples list_of_function_tuples: List( |
90 |
| - #(String, any), |
91 |
| - )) -> any |
| 59 | +fn benchee_wrapper_run( |
| 60 | + list_of_function_tuples list_of_function_tuples: List(#(String, any)), |
| 61 | +) -> any |
0 commit comments