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.
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
But of course, benchmarks are in general very similar to statistics… Don’t trust them if you haven’t faked them yourself