mirror of
https://bitbucket.org/Mattrixwv/luaclasses.git
synced 2025-12-06 10:23:58 -05:00
Added a simple way to time program run times
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
#Ignore all Visual Studio Code files
|
||||
.vscode/*
|
||||
47
Stopwatch.lua
Normal file
47
Stopwatch.lua
Normal 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
|
||||
Reference in New Issue
Block a user