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

test() -> test(1.23).

test(F) when is_float(F) ->
    Self = self(),
    spawn(fun() -> tc(Self, 1000000, fun() -> float_to_list(F, []) end) end),
    receive
    Msg1 -> io:format("float_to_list(~f, [])               = ~p\n", [F, Msg1])
    end,
    spawn(fun() -> tc(Self, 1000000, fun() -> float_to_list(F, [{decimals, 4}]) end) end),
    receive
    Msg2 -> io:format("float_to_list(~f, [{decimals, 4}]) = ~p\n", [F, Msg2])
    end,
    spawn(fun() -> tc(Self, 1000000, fun() -> float_to_list(F) end) end),
    receive
    Msg3 -> io:format("float_to_list(~f) = ~p\n", [F, 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).
