Current section

Files

Jump to
gleamy_bench src gleamy_bench_example.erl
Raw

src/gleamy_bench_example.erl

-module(gleamy_bench_example).
-compile([no_auto_import, nowarn_unused_vars]).
-export([main/0]).
-spec fib1(integer()) -> integer().
fib1(N) ->
case N of
0 ->
0;
1 ->
1;
N@1 ->
fib1(N@1 - 1) + fib1(N@1 - 2)
end.
-spec do_fib2(integer(), integer(), integer()) -> integer().
do_fib2(A, B, N) ->
case N of
0 ->
A;
_ ->
do_fib2(B, A + B, N - 1)
end.
-spec fib2(integer()) -> integer().
fib2(N) ->
do_fib2(0, 1, N).
-spec main() -> nil.
main() ->
_pipe = {bench,
[{input, <<"n=5"/utf8>>, 5},
{input, <<"n=10"/utf8>>, 10},
{input, <<"n=15"/utf8>>, 15}],
[{function, <<"fib1"/utf8>>, fun fib1/1},
{function, <<"fib2"/utf8>>, fun fib2/1}]},
_pipe@1 = gleamy_bench:run(_pipe, [{bench_time, 100}]),
_pipe@2 = gleamy_bench:table(_pipe@1, [ips, min, {p, 99}]),
gleam@io:println(_pipe@2).