Python Dictionaries and Mappings Performance -
many algorithms need map key data value. let's need map entity entity.
map = {} obj1 = classa() obj2 = classb() now can in 2 different ways:
map[obj1] = obj2 or
map[obj1.uniquename] = obj2 which version expert use? or version faster?
is better (faster) use string key or entity itself? there performance difference @ all?
there 2 main things impact performance here:
- the speed of hash()-method. (that is,
__hash__) - how hashes collide.
string hashing both fast , has properties, means hashing unique string default choice. however, if can provide fast , collision-free hash-function of class optimal choice.
(personally, i'd go strings, because of laziness.)
Comments
Post a Comment