Difference between revisions of "love.timer.getTime"

m (Clarified the function description.)
m (Made example a bit more practical)
Line 14: Line 14:
 
<source lang="lua">
 
<source lang="lua">
 
foo = ""
 
foo = ""
stime = love.timer.getTime()
+
local stime = love.timer.getTime()
  
 
for i=1,1000 do
 
for i=1,1000 do
Line 20: Line 20:
 
end
 
end
  
etime = love.timer.getTime()
+
local etime = love.timer.getTime()
print("It took " .. (etime-stime) .. " to concatenate 'bar' 1000 times!")
+
print(string.format("It took %.3f milliseconds to concatenate 'bar' 1000 times!", 1000 * (etime - stime)))
 
</source>
 
</source>
 
== See Also ==
 
== See Also ==

Revision as of 01:58, 25 August 2013

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.

Examples

Checking how long something takes

foo = ""
local stime = love.timer.getTime()

for i=1,1000 do
	foo = foo .. "bar"
end

local etime = love.timer.getTime()
print(string.format("It took %.3f milliseconds to concatenate 'bar' 1000 times!", 1000 * (etime - stime)))

See Also


Other Languages