apoorv-2204
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)
}
Marked As Solved
benwilson512
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.
Also Liked
benwilson512
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.
Rik
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.







