Skip to content

Instantly share code, notes, and snippets.

@shino
Created August 15, 2014 07:59
Show Gist options
  • Save shino/5835263ec70ced844075 to your computer and use it in GitHub Desktop.
Save shino/5835263ec70ced844075 to your computer and use it in GitHub Desktop.
-module(httpd_util_rfc1123_date).
-compile(export_all).
run() ->
CountPerProcess = 100,
L = erlang:localtime(),
io:format("Arity 0:"),
bmp0(fun() -> httpd_util:rfc1123_date() end, CountPerProcess, 10),
io:nl(),
io:format("Arity 1:"),
bmp0(fun() -> httpd_util:rfc1123_date(L) end, CountPerProcess, 10),
ok.
bmp0(Fun, CountPerProcess, Processes) ->
Self = self(),
ListOfPid = [spawn(fun() -> bmp_process(Self, Fun, CountPerProcess) end) ||
_ <- lists:seq(1, Processes)],
[Pid ! start || Pid <- ListOfPid],
ListOfUSec = [receive {_, USec, _Count} -> USec end || _Pid <- ListOfPid],
%% ?debugVal(ListOfUSec),
io:nl(),
io:format("============ Turn around time ================~n"),
io:format("Minimum~n"),
bm_format(lists:min(ListOfUSec), CountPerProcess, msec),
io:format("Maximum~n"),
bm_format(lists:max(ListOfUSec), CountPerProcess, msec),
TotalUSec = lists:sum(ListOfUSec),
io:format("Average~n"),
bm_format(TotalUSec div Processes, CountPerProcess, msec),
io:format("============ Throughput ======================~n"),
io:format("~f [ops/msec]~n", [CountPerProcess * Processes / (TotalUSec / Processes / 1000)]),
io:nl(),
ok.
bmp_process(From, Fun, Count) ->
receive
start ->
{USec, _Value} = timer:tc(fun() -> bm0(Fun, Count) end),
From ! {self(), USec, Count}
end.
bm0(_Fun, 0) ->
ok;
bm0(Fun, Count) ->
Fun(),
bm0(Fun, Count - 1).
bm_format(USec, Count) ->
%% ?debugVal(USec),
io:nl(),
bm_format(USec, Count, both).
bm_format(USec, Count, usec) ->
io:format("total: ~B [usec] / ~B [ops]~n", [USec, Count]),
io:format("single: ~f [usec/op]~n", [USec / Count]);
bm_format(USec, Count, msec) ->
io:format("total: ~f [msec] / ~B [ops]~n", [USec / 1000, Count]),
io:format("single: ~f [msec/op]~n", [USec / 1000 / Count]);
bm_format(USec, Count, both) ->
io:format("============= [in micro seconds] =============~n"),
bm_format(USec, Count, usec),
io:format("============= [in milli seconds] =============~n"),
bm_format(USec, Count, msec),
io:format("==============================================~n").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment