When benchmarking a function, what is measured?

If calling different modules and methods inside benchmarking functions also measures their execution also? if sending a message to a process for processing other things , does it include that processing of that process.

scenario = %{
“any” => fn _x → “I mean here” end)
}

1 Like

No, it only measures the time required to execute the function. If the function is not awaiting on the processing of another process, then neither will your benchmark.

waiting includes , driver function waiting for a message from another process through receive?

Yes. Think of it this way:

The benchmark is just doing (basically):

start_time = System.now()
function()
end_time = System.now()

end_time - start_time

So if something delays the return of function() then it will delay end_time. If it does not delay the return of function() then it does not.

5 Likes

Waiting for message from another elixir process will also increase the benchmark time?
Thanks

Yes. receive do blocks until it receives a message, which means it’ll block the return of the function, which means it’ll take more time in the benchmark.

1 Like

From documentation Processes - The Elixir programming language :

A timeout can also be specified:

iex> receive do
...>   {:hello, msg}  -> msg
...> after
...>   1_000 -> "nothing after 1s"
...> end
"nothing after 1s"

A timeout of 0 can be given when you already expect the message to be in the mailbox.

1 Like