Difference between revisions of "love.timer.getTime"
m (Add PrettySince field.) |
m (Cleaned up example a bit) |
||
Line 13: | Line 13: | ||
=== Checking how long something takes === | === Checking how long something takes === | ||
<source lang="lua"> | <source lang="lua"> | ||
− | + | local start = love.timer.getTime() | |
− | local | ||
− | for | + | -- Concatenate "bar" 1000 times. |
+ | local foo = "" | ||
+ | for _ = 1, 1000 do | ||
foo = foo .. "bar" | foo = foo .. "bar" | ||
end | end | ||
− | local | + | -- Resulting time difference in seconds. Multiplying it by 1000 gives us the value in milliseconds. |
− | print(string.format("It took %.3f milliseconds to concatenate 'bar' 1000 times!", 1000 | + | local result = love.timer.getTime() - start |
+ | print( string.format( "It took %.3f milliseconds to concatenate 'bar' 1000 times!", result * 1000 )) | ||
</source> | </source> | ||
== See Also == | == See Also == |
Revision as of 12:59, 7 July 2016
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.
Contents
Function
Synopsis
time = love.timer.getTime( )
Arguments
None.
Returns
number time
- The time in seconds.
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
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info