Get the current time with sub-second precision for benchmarking and performance measurement.
timer()
None
Current time as a number (seconds since epoch) with fractional/decimal precision for measuring elapsed time.
Simple elapsed time measurement:
start = timer()
// do some work
elapsed = timer() - start
print("Took " + elapsed + " seconds")
Benchmark a function:
function do_work()
// some expensive operation
end
iterations = 1000
start = timer()
for i = 0, iterations do
do_work()
end
elapsed = timer() - start
avg = elapsed / iterations
print("Average per iteration: " + avg + " seconds")
Measure with millisecond precision:
start = timer()
// do something
elapsed_ms = (timer() - start) * 1000
print("Took " + elapsed_ms + " ms")
timer() is optimized for measuring short intervals and provides decimal/fractional seconds. For getting the current timestamp for logging or data purposes, use now() or timestamp() instead.