diff options
author | Qi Liu <[email protected]> | 2016-03-11 18:18:59 +0800 |
---|---|---|
committer | Qi Liu <[email protected]> | 2016-03-11 18:18:59 +0800 |
commit | 2f46a5e2b37a054f482f76f4ac3d26b144cf988f (patch) | |
tree | e442e76741d664a29924c5f0ec6cc72e87345539 /lua/timer.lua | |
parent | 13729e83219cd90e33f329c49a50f6f4a4420721 (diff) |
add lua
Diffstat (limited to 'lua/timer.lua')
-rw-r--r-- | lua/timer.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lua/timer.lua b/lua/timer.lua new file mode 100644 index 0000000..2c54ca8 --- /dev/null +++ b/lua/timer.lua @@ -0,0 +1,33 @@ +local Timer = nerv.class("nerv.Timer") + +function Timer:__init() + self.last = {} + self.rec = {} +end + +function Timer:tic(item) + self.last[item] = os.clock() +end + +function Timer:toc(item) + if (self.last[item] == nil) then + nerv.error("item not there") + end + if (self.rec[item] == nil) then + self.rec[item] = 0 + end + self.rec[item] = self.rec[item] + os.clock() - self.last[item] +end + +function Timer:check(item) + if self.rec[item]==nil then + nerv.error('item not there') + end + nerv.printf('"%s" lasts for %f secs.\n',item,self.rec[item]) +end + +function Timer:flush() + for key, value in pairs(self.rec) do + self.rec[key] = nil + end +end |