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:

  1. the speed of hash()-method. (that is, __hash__)
  2. 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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -