Module:Sandbox/Fewfre/perf

local data = require('Module:Item/ApiData')

local p = {}

function p.listAllItems local t = {} for key,val in pairs(data.items) do		local skipLink = string.match(val.name, "Minion") or val.category == "DUNGEON_PASS" or string.match(val.id, "_SKIN_") or string.match(val.id, "PERFECT_") or string.match(val.id, "MASTER_SKULL_TIER_") t[#t+1] = " "..table.concat({			skipLink and val.name or ""..val.name.."",			string.match(val.name, "Minion") and "MINION" or '',			val.material,			val.id,			val.date,		}, "  ").."  " end return table.concat{ " "	} end

local customLibUtil = require('Module:LibraryUtil') local libraryUtil = require( 'libraryUtil' )

local COUNT = 500000 function testPerformance(name, func) mw.log("TEST: "..name) local start = os.clock func mw.log(" done - "..(os.clock - start)) end

function checkTypeSingle(name, argIdx, arg, allowedType, nilOk) local argType = type(arg) if argType == allowedType or (nilOk and arg == nil) then return arg end -- else invalid ({ checkType=error }).checkType(string.format("bad argument #%d to '%s' (%s expected, got %s)", argIdx, name, expectTypes, argType), 3) end

function checkTypeListOnly(name, argIdx, arg, allowedList) local argType = type(arg) for i=1, #allowedList do   if allowedList[i] == argType then return arg end end

({ checkType=error }).checkType(string.format("bad argument #%d to '%s' (%s expected, got %s)", argIdx, name, table.concat(expectTypes, '/'), argType), 3) end

-- local p = {}

function p.test testPerformance("checkTypeLight-single", function		local arg = {"foo"}		for i=COUNT,1,-1 do			checkTypeLight("foo", 1, arg, "table", true)		end	end) testPerformance("libraryUtil.checkType", function		local arg = {"foo"}		for i=COUNT,1,-1 do			libraryUtil.checkType("foo", 1, arg, "table", true)		end	end)

testPerformance("checkTypeSingle", function		local arg = {"foo"}		for i=COUNT,1,-1 do			checkTypeSingle("foo", 1, arg, "table", true)		end	end) testPerformance("checkTypeLight-multi", function		local arg = {"foo"}		for i=COUNT,1,-1 do			checkTypeLight("foo", 1, arg, { "string", "table", 'nil' })		end	end) testPerformance("libraryUtil.checkTypeMulti", function		local arg = {"foo"}		for i=COUNT,1,-1 do			libraryUtil.checkTypeMulti("foo", 1, arg, { "string", "table", 'nil' })		end	end)

testPerformance("checkTypeListOnly", function		local arg = {"foo"}		for i=COUNT,1,-1 do			checkTypeListOnly("foo", 1, arg, { "string", "table", 'nil' })		end	end) end

return p