Files
LuaClasses/Stopwatch.lua

48 lines
842 B
Lua

--luaClasses/Stopwatch.lua
--Matthew Ellison
-- Created: 2-1-19
--Modified: 2-1-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:getMilliseconds()
return math.floor((self:getTime() * 1000))
end
function Stopwatch:getSeconds()
return self:getTime()
end
function Stopwatch:getMinutes()
return (self:getTime() / 60)
end