
---- An object implementing averaged performance monitoring ----
-------------------------------------------------------------------------------

Timing = {
	timer = Timer.new(),
	LL = 60, -- Number of ticks to average over (60 = 1 second (if you're lucky ;)))
	list = {}, -- Table used as circular buffer
	index = 1
}

function Timing:tick()
	self.index = math.mod(self.index, self.LL) + 1
	self.list[self.index] = self.timer:time()
	self.timer:stop()
end

function Timing:start()
	self.timer:start()
end

function Timing:getTime()
	local pastindex = (self.index ~= self.LL) and self.index+1 or 1
	if self.list[pastindex] then
		return ((self.list[self.index] - self.list[pastindex]) / self.LL)
	else
		return 0
	end
end
