Added a simple way to time program run times

This commit is contained in:
2019-02-01 15:21:20 -05:00
parent dfdbae14bf
commit af09b185dc
2 changed files with 49 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
#Ignore all Visual Studio Code files
.vscode/*

47
Stopwatch.lua Normal file
View File

@@ -0,0 +1,47 @@
--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