Skip to content

Commit

Permalink
Replace benchmark functions
Browse files Browse the repository at this point in the history
  • Loading branch information
raethkcj committed Oct 21, 2023
1 parent 947faa3 commit 2a9f4db
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 121 deletions.
64 changes: 42 additions & 22 deletions RatingBuster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3637,27 +3637,47 @@ function RatingBuster:StatSummary(tooltip, name, link)
WriteSummary(tooltip, output)
end

function RatingBuster:PerformanceProfile()
if not GetCVarBool("scriptProfile") then
print("The console variable \"scriptProfile\" must be enabled to do performance profiling.\nEnable it and reload to continue. Be sure to disable it again when you are finished.")
return
end

-- RatingBuster:Bench(1000)
---------
-- self:RecursivelySplitLine("+24 Agility/+4 Stamina, +4 Dodge and +4 Spell Crit/+5 Spirit", {"/", " and ", ","})
-- 1000 times: 0.16 - 0.18 without Compost
-- 1000 times: 0.22 - 0.24 with Compost
---------
-- RatingBuster.ProcessTooltip(ItemRefTooltip, link)
-- 1000 times: 0.31 sec - 0.7.6
-- 1000 times: 0.29 sec - 0.
-- 1000 times: 0.24 sec - 0.8.58.0
---------
-- strjoin 1000000 times: 0.46
-- .. 1000000 times: 0.27
--------------
function RatingBuster:Bench(k)
local t1 = GetTime()
local link = GetInventoryItemLink("player", 12)
for i = 1, k, 1 do
ItemRefTooltip:SetInventoryItem("player", 12)
RatingBuster.ProcessTooltip(ItemRefTooltip, link)
-- Process the tooltips for all of the player's equipped gear
for i = INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED do
GameTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE")
GameTooltip:SetInventoryItem("player", i)
self.ProcessTooltip(GameTooltip)
GameTooltip:Hide()
end
return GetTime() - t1
end

local tables = {
["RatingBuster"] = self,
["StatLogic"] = StatLogic
}

for name, addonTable in pairs(tables) do
print(name)
print("(ms) (count) (function)")
local unsorted = {}
local rankings = {}
for k,v in pairs(addonTable) do
if type(v) == "function" then
local time, count = GetFunctionCPUUsage(v, false)
if count > 0 then
unsorted[time] = {
count = count,
name = k
}
tinsert(rankings, time)
end
end
end
table.sort(rankings, function(a,b) return a > b end)
for i, time in ipairs(rankings) do
if i <= 10 then
print(string.format(" %2.2f %4d %s", time, unsorted[time].count, unsorted[time].name))
end
end
end
end
100 changes: 1 addition & 99 deletions libs/StatLogic/StatLogic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3143,102 +3143,4 @@ function StatLogic:GetDiff(item, diff1, diff2, ignoreEnchant, ignoreGems, ignore
end
-- return tables
return diff1, diff2
end


-----------
-- DEBUG --
-----------
-- StatLogic:Bench(1000)
---------
-- self:GetSum(link, table)
-- 1000 times: 0.82 sec without cache
-- 1000 times: 0.04 sec with cache
---------
-- ItemBonusLib:ScanItemLink(link)
-- 1000 times: 1.58 sec
---------
function StatLogic:Bench(k)
local t1 = GetTime()
local link = GetInventoryItemLink("player", 12)
--local GetItemInfo = _G["GetItemInfo"]
for i = 1, k, 1 do
---------------------------------------------------------------------------
--self:SplitDoJoin("+24 Agility/+4 Stamina, +4 Dodge and +4 Spell Crit/+5 Spirit", {"/", " and ", ","})
---------------------------------------------------------------------------
--self:GetSum(link)
--ItemBonusLib:ScanItemLink(link)
---------------------------------------------------------------------------
--ItemRefTooltip:SetScript("OnTooltipSetItem", function(frame, ...) RatingBuster:Print("OnTooltipSetItem") end)
---------------------------------------------------------------------------
GetItemInfo(link)
end
return GetTime() - t1
end


function StatLogic:PatternTest()
local patternTable = {
"(%a[%a ]+%a) ?%d* ?%a* by u?p? ?t?o? ?(%d+) ?a?n?d? ?", -- xxx xxx by 22 (scan first)
"(%a[%a ]+) %+(%d+) ?a?n?d? ?", -- xxx xxx +22 (scan 2ed)
"(%d+) ([%a ]+) ?a?n?d? ?", -- 22 xxx xxx (scan last)
}
local textTable = {
"Spell Damage +6 and Spell Hit Rating +5",
"+3 Stamina, +4 Critical Strike Rating",
"+26 Healing Spells & 2% Reduced Threat",
"+3 Stamina/+4 Critical Strike Rating",
"Socket Bonus: 2 mana per 5 sec.",
"Equip: Increases damage and healing done by magical spells and effects by up to 150.",
"Equip: Increases the spell critical strike rating of all party members within 30 yards by 28.",
"Equip: Increases damage and healing done by magical spells and effects of all party members within 30 yards by up to 33.",
"Equip: Increases healing done by magical spells and effects of all party members within 30 yards by up to 62.",
"Equip: Increases your spell damage by up to 120 and your healing by up to 300.",
"Equip: Restores 11 mana per 5 seconds to all party members within 30 yards.",
"Equip: Increases healing done by spells and effects by up to 300.",
"Equip: Increases attack power by 420 in Cat, Bear, Dire Bear, and Moonkin forms only.",
}
for _, text in ipairs(textTable) do
DEFAULT_CHAT_FRAME:AddMessage(text.." = ")
for _, pattern in ipairs(patternTable) do
local found
for k, v in text:gmatch(pattern) do
found = true
DEFAULT_CHAT_FRAME:AddMessage(" '"..k.."', '"..v.."'")
end
if found then
DEFAULT_CHAT_FRAME:AddMessage(" using: "..pattern)
DEFAULT_CHAT_FRAME:AddMessage("----------------------------")
break
end
end
end
end

----------------------
-- Register Library --
----------------------

----------------------
-- API doc template --
----------------------
--[[---------------------------------
{ :GetDiff(item, [table1], [table2])
-------------------------------------
-- Description
Calculates the stat diffrence from item and equipped items
-- Args
item
string - link or name of target item
or number - itemID of target item
or table - tooltip of target item
[table1]
table - stat difference of item and equipped item 1 are writen to this table if provided
[table2]
table - stat difference of item and equipped item 2 are writen to this table if provided
-- Remarks
-- Examples
StatLogic:GetDiff(21417, {}) -- Ring of Unspoken Names
StatLogic:GetDiff(21452) -- Staff of the Ruins
}
-----------------------------------]]
end

0 comments on commit 2a9f4db

Please sign in to comment.