Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
The idea is to create M x N threads, and measure the time cost for every N threads created. After a thread is created, it sends a message to let the main process continue, and finishes execution.
-module(tcbenchnb).
-export([start/2, init/2, thread/1]).
start(Total_Rounds, Step) ->
spawn(?MODULE, init, [Total_Rounds, Step]).
init(Total_Rounds, Step) ->
Start_Time = os:timestamp(),
create_threads(0, 0, Total_Rounds, Step, Start_Time).
create_threads(Total_Rounds, _, Total_Rounds, _, _) ->
init:stop();
create_threads(Round, Step, Total_Rounds, Step, Last_Time) ->
wait_threads(Round, 0, Total_Rounds, Step, Last_Time);
create_threads(Round, Created, Total_Rounds, Step, Last_Time) ->
spawn(?MODULE, thread, [self()]),
create_threads(Round, Created+1, Total_Rounds, Step, Last_Time).
wait_threads(Round, Step, Total_Rounds, Step, Last_Time) ->
Time = os:timestamp(),
Diff = timer:now_diff(Time, Last_Time),
io:format("~p~n", [Diff div 1000]),
create_threads(Round+1, 0, Total_Rounds, Step, Time);
wait_threads(Round, Started, Total_Rounds, Step, Last_Time) ->
receive
started ->
wait_threads(Round, Started+1, Total_Rounds, Step, Last_Time)
end.
thread(Parent) ->
Parent ! started.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.