performancetimelua

trying to see how long a Lua script takes to finish executing


I'm trying to make my Lua script tell me how long it took until the entire script was executed, for improvement reasons

I've tried using functions like os.clock(), os.time() and os.difftime() in countless ways over the internet to achieve this result but they always return 0 at the end. Does anyone know how I can do this?


Solution

  • local before = os.clock()
    
    for i = 1, 1e6 do
       local double = i * 2
    end
    
    local after = os.clock()
    
    print(string.format("Loop took %0.6f seconds to run", after - before))