-module(test).
-export([test/0]).

test() ->
    Self = self(),
    spawn(fun() -> tc(Self, 1000000, fun() -> float_to_list(123.4, []) end) end),
    receive
    Msg1 -> io:format("float_to_list(123.4, [])               = ~p\n", [Msg1])
    end,
    spawn(fun() -> tc(Self, 1000000, fun() -> float_to_list(123.4, [{precision, 4}]) end) end),
    receive
    Msg2 -> io:format("float_to_list(123.4, [{precision, 4}]) = ~p\n", [Msg2])
    end,
    spawn(fun() -> tc(Self, 1000000, fun() -> float_to_list(123.4, 4) end) end),
    receive
    Msg3 -> io:format("float_to_list(123.4, 4)                = ~p\n", [Msg3])
    end.


tc(Pid, N, F) when N > 0 ->
    loop(Pid, N, N, F, erlang:now()).

loop(Pid, 1, N, F, Time1) ->
    Res = F(),
    Int = timer:now_diff(erlang:now(), Time1),
    Pid ! {Int / N, Res};
loop(Pid, N, X, F, Time1) ->
    F(),
    loop(Pid, N-1, X, F, Time1).
