Module:Sandbox/Fewfre/perf

local getArgs = require('Module:Arguments').getArgs local data = require('Module:Item/ApiData') local p = {}

function p._pageExistsNotWantedPage(frame) local args = getArgs(frame) return p.pageExistsNotWantedPage(args[1]) and "true" or "false" end

-- checks if a page exists without marking it as a Special:WantedPages -- [EXPENSIVE] Note that just like a normal page `exists` check, this is an expensive function function p.pageExistsNotWantedPage(pagename) local frame = mw.getCurrentFrame -- PROTECTIONEXPIRY is a magic word that lets us check a page in a roundabout way without maerking it as wanted. -- Info from: https://www.mediawiki.org/wiki/Extension_talk:Scribunto/Lua_reference_manual#Avoid_creating_a_wanted_page_link_when_checking_if_page_exist return frame:callParserFunction('PROTECTIONEXPIRY:edit', pagename) ~= '' end

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