os.difftime

Calculates a time difference in seconds

Prototype

n = os.difftime (t1, t2)

Description

Returns the number of seconds from time t1 to time t2.

In other words, the result is t1 - t2.

tstart = os.time ()
-- do something lengthy here ..
tend = os.time ()
print (os.difftime (tend , tstart)) --> 3
When using MUSHclient (ie. this is not standard Lua) you can get better resolution by using GetInfo (which uses the Windows "high performance" timer), like this:

tstart = GetInfo (232)  -- get high-resolution timer value
-- do something lengthy here ..
tend = GetInfo (232)    
print (string.format ("Time taken = %1.3f seconds", tend - tstart))

Lua functions

Topics