diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5c4c096 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +#Ignore all Visual Studio Code files +.vscode/* \ No newline at end of file diff --git a/Stopwatch.lua b/Stopwatch.lua new file mode 100644 index 0000000..78ee332 --- /dev/null +++ b/Stopwatch.lua @@ -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