Skip to content

Instantly share code, notes, and snippets.

@bryanhunter
Created February 11, 2014 19:10
Show Gist options
  • Save bryanhunter/8941851 to your computer and use it in GitHub Desktop.
Save bryanhunter/8941851 to your computer and use it in GitHub Desktop.
Simple program to test the performance of a concurrent language.
-module(mike_check).
% The performance of a concurrent language is predicated by three things:
% 1) the context switching time,
% 2) The message passing time,
% 3) and the time to create a process.”
% - Mike Williams
-export([start_and_time/1,start/1, do_it_all/2]).
start_and_time(HowMany)->
{Microseconds, _} = timer:tc(?MODULE, start, [HowMany]),
io:format("~nCompleted in ~p seconds (~p microseconds per process).~n",
[Microseconds/1000000, Microseconds/HowMany]).
start(HowMany) ->
do_it_all(HowMany, self()).
do_it_all(0, FirstCallersPid) ->
FirstCallersPid ! yolo;
do_it_all(HowManyMore, FirstCallersPid) ->
%% Create a child process
ChildsPid = spawn(?MODULE, do_it_all,
[HowManyMore-1, FirstCallersPid]),
%% Send a 'yolo' message to our child process
ChildsPid ! yolo,
%% Hang here until we receive a 'yolo' message (from our parent).
receive yolo ->
%% It's been a rich, full life...
croak
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment