How much time my script/function took to execute?

Hi, as my question says.
I’m doing exercises to get used to the language, in a webpage with the solution of my problem(they used c# I believe), they output at the end: Solution took 0 ms. How to do this with Elixir?

Right now I’m just making easy programs, so its not a big deal, but I would like to know this kind of stuff that I will/might use it near in the future.


You can use Elrang function


So you are asking about micro benchmark?


As long as your programs remain self enclosed and you are interested in the overal runtime, you don’t need to time inside of your script.

*nix-Systems have the command time which measures runtime of your executable and MS-PowerShell has Measure-Command which shall do similar things¹

¹: According to a post on SESU


Of course, using the time command-line utility will also include all the time that is necessary to start Erlang’s Virtual Machine and shut it down. Depending on your needs, this might be what you want, or it might not.


time is the answer to the question “how much time my script took to execute?” and of course it is the only valid answer. Warming up the VM and maybe precompiling the module do belong to the execution time of the full script. When you are required to print the result on screen in less than a minute and your VM needs 5 minutes for warming up, you have choosen the wrong system.

Of course, when you want to know how long a single function or a sequence of functions took, there are more accurate tools available in Erlang and Elixir that do a much better job than time for this usecase :wink:

But of course, benchmarks are in general very similar to statistics… Don’t trust them if you haven’t faked them yourself :wink:


Thanks all for their replies, I just selected the best one since it gave me good explaination about it, the first one was good too.