Os.clock(), what is it for?

Hello! As of recently I have been looking into the os library, I understood os.time() and os.date() pretty well. However I did not understand os.clock(). I assume it is related with the CPU clock. But I am not sure.

I think your correct based on the reading, it looks like its just the devices time when you run the line

local startTime = os.clock()

According to documentation, os.clock Returns the amount of CPU time used by Lua in seconds. It has a precision of about 1 microseconds and the intended use is benchmarking. From my experience, os.clock is incredible useful for certain situations where high precision is required, like for example counting the amount of time a function takes to run(in milliseconds) or trying to make a realistic timer with decimal precision.

2 Likes