Skip to content

Instantly share code, notes, and snippets.

Eshell V5.7.4 (abort with ^G)
1> c(e26).
{ok,e26}
2> e26:ringBenchmark(4, "Hello", 5).
Spawned with NextNode []
Spawned with NextNode <0.39.0>
Spawned with NextNode <0.40.0>
Spawned with NextNode <0.41.0>
Spawned with NextNode <0.42.0>
Message '"Hello"' with NumberOfHops 20
-module (e26).
-compile (export_all).
ringBenchmark(NumberOfNodes, Message, NumberOfLaps) ->
statistics(runtime),
statistics(wall_clock),
FirstNode = spawn(?MODULE, loop, [[]]),
LastNode = createNode(1, NumberOfNodes, FirstNode),
FirstNode ! LastNode,
Eshell V5.7.4 (abort with ^G)
1> c(e25).
{ok,e25}
2> e25:ringBenchmark(4, "Hello", 5).
Sent 20 messages in time=0 (0) milliseconds
Spawned with NextNode []
Spawned with NextNode <0.39.0>
Spawned with NextNode <0.40.0>
Spawned with NextNode <0.41.0>
Spawned with NextNode <0.42.0>
-module (e25).
-compile (export_all).
ringBenchmark(NumberOfNodes, Message, NumberOfLaps) ->
statistics(runtime),
statistics(wall_clock),
FirstNode = spawn(?MODULE, loop, [[]]),
LastNode = createNode(1, NumberOfNodes, FirstNode),
FirstNode ! LastNode,
loop(NextNode) ->
io:format("Spawned with NextNode ~p~n", [NextNode]),
receive
{_From, Message, NumberOfHops} ->
io:format("Message '~p' with NumberOfHops ~p~n", [Message, NumberOfHops]),
sendMessage(Message, NextNode, NumberOfHops - 1),
loop(NextNode);
NewNext when NextNode =:= [] ->
loop(NewNext)
sendMessage(_Message, _ToNode, 0) -> void;
sendMessage(Message, ToNode, NumberOfHops) ->
ToNode ! {self(), Message, NumberOfHops}.
Eshell V5.7.4 (abort with ^G)
1> c(e24).
{ok,e24}
2> e24:ringBenchmark(4, "Hello", 5).
Sent 20 messages in time=0 (0) milliseconds
Spawned with NextNode []
Spawned with NextNode <0.39.0>
Spawned with NextNode <0.40.0>
Spawned with NextNode <0.41.0>
Spawned with NextNode <0.42.0>
NewNext when NextNode =:= [] ->
loop(NewNext)
loop(NextNode) ->
io:format("Spawned with NextNode ~p~n", [NextNode]),
receive
NewNext when NextNode =:= [] ->
loop(NewNext)
end.
FirstNode ! LastNode,