mirror of
https://bitbucket.org/Mattrixwv/luaclasses.git
synced 2025-12-06 18:33:59 -05:00
52 lines
921 B
Lua
52 lines
921 B
Lua
--luaClasses/Stopwatch.lua
|
|
--Matthew Ellison
|
|
-- Created: 02-01-19
|
|
--Modified: 02-06-19
|
|
--This is a simple class to be used to time runtimes of various things within programs
|
|
|
|
Stopwatch = {
|
|
startTime = 0,
|
|
stopTime = 0
|
|
}
|
|
Stopwatch.__index = Stopwatch
|
|
|
|
function Stopwatch:create()
|
|
local timer = {}
|
|
setmetatable(timer, Stopwatch)
|
|
return timer
|
|
end
|
|
|
|
function Stopwatch:start()
|
|
self.startTime = os.clock()
|
|
self.stopTime = 0
|
|
end
|
|
|
|
function Stopwatch:stop()
|
|
self.stopTime = os.clock()
|
|
end
|
|
|
|
function Stopwatch:reset()
|
|
self.startTime = 0
|
|
self.stopTime = 0
|
|
end
|
|
|
|
function Stopwatch:getTime()
|
|
return (self.stopTime - self.startTime)
|
|
end
|
|
|
|
function Stopwatch:getMicroseconds()
|
|
return math.floor(self:getTime() * 1000000)
|
|
end
|
|
|
|
function Stopwatch:getMilliseconds()
|
|
return (self:getTime() * 1000)
|
|
end
|
|
|
|
function Stopwatch:getSeconds()
|
|
return self:getTime()
|
|
end
|
|
|
|
function Stopwatch:getMinutes()
|
|
return (self:getTime() / 60)
|
|
end
|