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.)
GetGameTime
took 0.000384sGetEntPropString
took 0.010754s
The above are just baseline values on known 'simple' operations for reference
TF2Attrib_HookValueFloat
took 0.037156s
TF2Attrib_HookValueFloat
iterates over all items on a player if given a player entity to hook
TF2Attrib_GetStringValue
took 0.116503sTF2Attrib_GetStringValue
(missing) took 1.443081s
TF2Attrib_GetStringValue
does naive lookups and doesn't take advantage of the attrib cache
TF2Attrib_HookValueString
took 0.081578sTF2Attrib_HookValueString
(missing) took 0.079989s
TF2Attrib_HookValueString
does caching and iterates over all player items
TF2CustAttr_GetInt
took 0.044222sTF2CustAttr_GetFloat
took 0.048780sTF2CustAttr_GetString
took 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_GetString
is ~40% faster thanTF2Attrib_HookValueString
TF2Attrib_HookValueString
is ~75% faster thanTF2Attrib_GetStringValue
in the optimal case where the attribute exists as a runtime attribute, and 1800% faster thanTF2Attrib_GetStringValue
in the worst case where the attribute doesn't exist on an entity (since it iterates over runtime / SOC / static).TF2Attrib_GetStringValue
is literally dead on arrival, since it's not even on a public release branch yet!