Skip to content

Instantly share code, notes, and snippets.

@seancribbs
Forked from kevsmith/bench.erl
Last active December 14, 2015 07:18
Show Gist options
  • Save seancribbs/5049084 to your computer and use it in GitHub Desktop.
Save seancribbs/5049084 to your computer and use it in GitHub Desktop.
-module(bench).
-export([run/1]).
run(Count) ->
Me = self(),
timer:tc(fun() -> run(Me, Count) end).
run(Me, Count) ->
F = spawn(fun() -> worker(Me, Count) end),
spawn(fun() -> worker(Me, F, Count) end),
wait_for_done(2).
wait_for_done(0) ->
ok;
wait_for_done(Count) ->
receive
done ->
wait_for_done(Count - 1)
end.
worker(Owner, 0) ->
Owner ! done;
worker(Owner, Count) ->
receive
{From, ping} ->
From ! pong,
worker(Owner, Count - 1)
end.
worker(Owner, _Target, 0) ->
Owner ! done;
worker(Owner, Target, Count) ->
Target ! {self(), ping},
receive
pong ->
worker(Owner, Target, Count - 1)
end.
---------------------------------------------------------------------------------
| Iteration | Message Count | R16B ET(us)   | R15B01 ET(us)   | R14B03 ET(us)   |
---------------------------------------------------------------------------------
|   1       |      1000000  |     3473396   |     1016343     |      927738     |
|   2       |      1000000  |     3613964   |     1089535     |      927751     |
|   3       |      1000000  |     3614176   |     1085716     |      930875     |
|   4       |      1000000  |     3627181   |     1075551     |      926532     |
|   5       |      1000000  |     3781928   |     1076596     |      954513     |
---------------------------------------------------------------------------------
| Average   |               |     3622129   |     1068748     |      933482     |
| Std. Dev  |               |      109331   |       29892     |       11806     |
---------------------------------------------------------------------------------

NOTE: Informal benchmark written in a few spare minutes.

All tests were run on an otherwise idle 2.7ghz Core i7 2011 MBP. Erlang command line: erl +K true +A 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment