Current section
Files
Jump to
Current section
Files
src/pocket_watch.erl
-module(pocket_watch).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([callback_us/3, callback/3, simple/2]).
-spec callback_us(binary(), fun((binary(), integer()) -> nil), fun(() -> HOQ)) -> HOQ.
callback_us(Label, Callback, Body) ->
Start = birl:monotonic_now(),
Res = Body(),
Elapsed = birl:monotonic_now() - Start,
Callback(Label, Elapsed),
Res.
-spec callback(binary(), fun((binary(), binary()) -> nil), fun(() -> HOP)) -> HOP.
callback(Label, Callback, Body) ->
Callback@1 = fun(Label@1, Elapsed) ->
Callback(Label@1, humanise:microseconds_int(Elapsed))
end,
callback_us(Label, Callback@1, Body).
-spec simple(binary(), fun(() -> HOO)) -> HOO.
simple(Label, Body) ->
Print_time = fun(Label@1, Elapsed) ->
gleam@io:println(
<<<<<<"pocket_watch ["/utf8, Label@1/binary>>/binary,
"]: took "/utf8>>/binary,
Elapsed/binary>>
)
end,
callback(Label, Print_time, Body).