Skip to content

Instantly share code, notes, and snippets.

@maruks
Created December 7, 2016 11:45
Show Gist options
  • Save maruks/0a2d5d92927b631d4231be615b115d61 to your computer and use it in GitHub Desktop.
Save maruks/0a2d5d92927b631d4231be615b115d61 to your computer and use it in GitHub Desktop.
GC benchmark ported to Erlang
-module(main).
-define(WINDOW_SIZE, 200000).
-define(MSG_COUNT, 1000000).
-define(MSG_SIZE, 1024).
-export([main/0]).
push_message(N) ->
Start = erlang:monotonic_time(),
Bin = list_to_binary(lists:duplicate(?MSG_SIZE, N rem 255)),
put(N, Bin),
Low = N - ?WINDOW_SIZE,
if
Low >= 0 -> erase(Low);
true -> nop
end,
Diff = erlang:monotonic_time() - Start,
erlang:convert_time_unit(Diff, native, millisecond).
push_all_messages(0, Time) ->
Time;
push_all_messages(Id, Time) ->
T = push_message(Id),
push_all_messages(Id - 1, max(Time, T)).
main() ->
MaxTime = push_all_messages(?MSG_COUNT, 0),
io:format("Worst push time ~p ~n",[MaxTime]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment