Module:Sandbox/Aidan9382/Benchmarker: Difference between revisions

Content deleted Content added
percentages
allow specifying a custom MinTimeTaken
 
(4 intermediate revisions by the same user not shown)
Line 1:
-- In-depth execution speed benchmarker - read the /doc for more info
 
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --
-- =================================================================== --
-- This is a meta-module that hooks lots of globals, andwhich cancould be disruptive --
-- Avoid using this outside of "Show preview" testing and sandboxes --
-- Be careful including this module outside of sandboxes --
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --
-- =================================================================== --
 
-- Always use rawget/rawset on _G to bypass strict
Line 56 ⟶ 57:
FunctionTotalTimes[UniqueName] = FunctionTotalTimes[UniqueName] + CallTime
end
local MinTimeTaken = rawget(_G, "_MinTimeTaken") or 0.01
table.sort(SeenModules, function(a, b)
if TotalTimeTaken > .01MinTimeTaken then
return ModuleTotalTimes[a] > ModuleTotalTimes[b]
table.sort(SeenModules, function(a, b)
end)
return ModuleTotalTimes[a] > ModuleTotalTimes[b]
table.sort(SeenFunctions, function(a, b)
end)
return FunctionTotalTimes[a] > FunctionTotalTimes[b]
table.sort(SeenFunctions, function(a, b)
end)
return FunctionTotalTimes[a] > FunctionTotalTimes[b]
if TotalTimeTaken > .01 then
end)
mw.log("\n-- Benchmarker Finished --")
mw.log("Total time taken: " .. dp(TotalTimeTaken)*1000 .. "ms")
Line 68 ⟶ 70:
for i = 1, math.min(5, #SeenModules) do
local t = dp(ModuleTotalTimes[SeenModules[i]])
mw.log(SeenModules[i] .. ": " .. t*1000 .. "ms (" .. dp(t/TotalTimeTaken, 3)*100 .. "%)")
end
mw.log("\nTop 5 functions by time taken:")
for i = 1, math.min(5, #SeenFunctions) do
local t = dp(FunctionTotalTimes[SeenFunctions[i]])
mw.log(SeenFunctions[i] .. ": " .. t*1000 .. "ms (" .. dp(t/TotalTimeTaken, 3)*100 .. "%)")
end
mw.log("") -- extra newline
Line 119 ⟶ 121:
end
end
return obj
end
rawset(_G, "_BenchmarkerHooker", HookTable)