What's the best way to calculate execution time of an application?

Hi Elixir developers!

I’ve created an elixir app wich creates a set of processes (about 900) with a lot of calculation distributed among all theese processes. I need to calculate the time spent between the started time and the last calculation (wich can occurr in any process). What’s the best way to calculate the execution time of my distributed application?

Thanks a lot!


{time_in_microseconds, ret_val} = :timer.tc(fn -> app.run() end)

Thanks for reply Massimo!

But in this case, the run() function ends up prior than the other 900 processes. I will have only the time spent for the mains process, not the others. I need to capture the moment the last process (in a known list) finished his job.

How do you know when a process has finished its job? Does it die, or tell someone, or does it just become dormant waiting for a message?

1 Like

I think two evidences get’s me the fact the process ended up its job: message queue empty and status waiting. Am I right?

Just wait for them to end.

something like

|> Enum.map(fn -> Task.async(fn -> do_some_work() end) end)
|> Enum.each(& Task.await(&1))

or use receive that blocks

I created a gist with a basic example of one possible implementation

1 Like

Got it! I’ll need to change my code a litle bit but I’ve got the idea! The goal is send a message to the main process when each sub-process finish his hob. God idea! Thank you!

1 Like

I’ve created a different way to check if the processes ended up their jobs. The main idea here is create a process wich will inspect all processes (I have all PIDs in a list) and check if they have message to be processed and their status is different from “waiting”. When all processes finished their message queue and set their status to “waiting” I will understand the job is done. The code is something like this:

def wait_up_to_end_all_process() do
# wait until all process have message queue empty and status is waiting
elements = get_element_list_total()

defp check_message_queue_loop(elements) do
if check_message_queue(elements) > 0 do

defp check_message_queue([]) do
0 #List empty - all elements are queue empty

defp check_message_queue([ pid | elements]) do
info = Process.info(pid)
count =
if info[:message_queue_len] == 0 and info[:status] == :waiting do
count + check_message_queue(elements)


Check this out and let me know if is that a good idea.

Busy waiting is definitely not a appropriate way to measure performance, b/c it directly affects performance by itself.