Instead of:
Code:
local fps = "|c00FFFFFF".. string.format("%0.i", GetFramerate()) .. " |rfps"
self.text:SetText(fps)
Use:
Code:
self.text:SetFormattedText("|cffffffff%0.i|r fps", GetFramerate())
This passes the
string.format operation to the C code backend instead of doing it in Lua, so it's faster, and creates less string garbage.
Also,
string.format can handle plain text, so you should just put all your text in the format string, instead of performing multiple concatenation operations and creating more strings.
Finally, in your original code, FPS_UPDATE and FPS_RATE are defined
global variables. You should avoid putting anything into the global namespace unless it's absolutely necessary, and when you do, make sure the names are unique (so, not FPS_RATE which is very generic and likely to collide with other addons leaking globals) and clearly identify them as belonging to your addon. In this case, it's not necessary, so you should not make them globals:
Code:
local font, size, flags = self.text:GetFont()
self.text:SetFont(font, size, "OUTLINE")
local _, class = UnitClass("player")
local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
self.text:SetTextColor(color.r, color.g, color.b)
self.text:SetJustifyH("CENTER")
self.text:SetJustifyV("CENTER")
self.update = 0
self.rate = 1
Code:
self.update = self.update + elapsed
if self.update >= self.rate then
self.text:SetFormattedText("|cffffffff%0.i|r fps", GetFramerate())
self.update = 0
end
Oh, and in color codes, you should always begin with "|cff", not "|c00". That first hex pair represents the opacity of the contained text. 00 represents 0% opacity, which is invisible. You want ff, which represents 100% opacity. In practice it isn't important because the opacity is ignored in most (if not all) contexts in WoW, but that's not an excuse for passing the wrong value. You want visible text, so you shouldn't specify that you want
invisible text and rely on the value being ignored -- just specify the value you actually want.