I sometimes see people that compare code efficency by execution time like here.
How can you create them (also for other languages)?
What do these values say?
Do they apply on every computer?
Scripts
How to determine the speed of code?
How to determine the speed of code?
1

local x = os.clock() -- your code to benchmark print(os.clock() - x)
Hajt: says is how to do it. Let me explain what it means:
for-loop, because most functions are so fast that you can't measure 1 run
the longer a loop the more accurate the comparison between functions
the result is always different on other hardware, even your current load will affect the results (don't run benchmarks whilst playing Crysis 3
) - process priority and stuff
with os.clock() you will get the time your Lua process is running and the difference between start and end times is how long your function took to execute. Afterwards you can calculate the difference in percent
VADemon has written
the result is always different on other hardware, even your current load will affect the results (don't run benchmarks whilst playing Crysis 3
) - process priority and stuff
Bowlinghead: No, as I already said: The values normally only differ a tiny bit when running on the same machine. Also executing stuff many times in a loop (like
VADemon said) can help to get better values. You could for instance run a snippet 100,000 times and then divide the resulting time by 100,000 so you get the average time for a single run.
1
