fresh benchmarks for attributes and attribute strings with some new optimizations on tf2attributes' side
(note that the optimizations only affect native attributes)
Running benchmark with 65536 iterations. (This benchmark was run multiple times, and the best time for each was taken.)
GetGameTimetook 0.000384sGetEntPropStringtook 0.010754s
The above are just baseline values on known 'simple' operations for reference
TF2Attrib_HookValueFloattook 0.037156s
TF2Attrib_HookValueFloat iterates over all items on a player if given a player entity to hook
TF2Attrib_GetStringValuetook 0.116503sTF2Attrib_GetStringValue(missing) took 1.443081s
TF2Attrib_GetStringValue does naive lookups and doesn't take advantage of the attrib cache
TF2Attrib_HookValueStringtook 0.081578sTF2Attrib_HookValueString(missing) took 0.079989s
TF2Attrib_HookValueString does caching and iterates over all player items
TF2CustAttr_GetInttook 0.044222sTF2CustAttr_GetFloattook 0.048780sTF2CustAttr_GetStringtook 0.051782s
custattr doesn't iterate over all items on a player, so you have to make multiple calls for an attribute that combines values — multiply the int / float bench times by at least 4x (player + 3 weapons) if you want to match hookvalue
tl;dr:
- native int / float hooks are faster than iterated calls to custattr int / float (they should be the same-ish speed for single entities)
TF2CustAttr_GetStringis ~40% faster thanTF2Attrib_HookValueStringTF2Attrib_HookValueStringis ~75% faster thanTF2Attrib_GetStringValuein the optimal case where the attribute exists as a runtime attribute, and 1800% faster thanTF2Attrib_GetStringValuein the worst case where the attribute doesn't exist on an entity (since it iterates over runtime / SOC / static).TF2Attrib_GetStringValueis literally dead on arrival, since it's not even on a public release branch yet!