Modul:Time it

Fra Wikipedia, den frie encyklopædi
Documentation icon Moduldokumentation[opret]
-- Time the execution time of a template
local p = {}
function p.time_it(frame)
	local args = (frame == mw.getCurrentFrame()) and frame:getParent().args or frame.args
	local template
	local template_args = {}
	for arg, value in pairs(args) do
		if type(arg) == 'number' then
			if arg == 1 then
				template = value
			else
				template_args[arg - 1] = value
			end
		else
			template_args[arg] = value
		end
	end
	if template then
		local clock = os.clock
		local time1 = clock()
		local result = frame:expandTemplate{title = template, args = template_args}
		local time2 = clock()
		return result .. ' (tid: ' .. time2 - time1 .. ' s)'
	end
end
return p