Difference between revisions of "love.timer.getTime"

m (Remove link to getMicroTime)
(Returns: Clarified the function a little. I personally found it difficult to understand at first glance and thought the time is an integer of seconds or microseconds)
Line 9: Line 9:
 
None.
 
None.
 
=== Returns ===
 
=== Returns ===
{{param|number|time|The time in seconds.}}
+
{{param|number|time|The time in seconds. Given as a decimal, accurate to the microsecond.}}
 +
 
 
== Examples ==
 
== Examples ==
 
=== Checking how long something takes ===
 
=== Checking how long something takes ===

Revision as of 17:29, 11 June 2017

Returns the value of a timer with an unspecified starting time. This function should only be used to calculate differences between points in time, as the starting time of the timer is unknown.

Function

Synopsis

time = love.timer.getTime( )

Arguments

None.

Returns

number time
The time in seconds. Given as a decimal, accurate to the microsecond.

Examples

Checking how long something takes

local start = love.timer.getTime()

-- Concatenate "bar" 1000 times.
local foo = ""
for _ = 1, 1000 do
	foo = foo .. "bar"
end

-- Resulting time difference in seconds. Multiplying it by 1000 gives us the value in milliseconds.
local result = love.timer.getTime() - start
print( string.format( "It took %.3f milliseconds to concatenate 'bar' 1000 times!", result * 1000 ))

See Also


Other Languages