2009/4/16 Francesco Cosoleto <[email protected]> > Nicolas Dumazet ha scritto: > > A small note here: set is not really meant to be used on incremental > > .add(), because sets are frozen (not mutable), and add() instantiates > > a new set on each .add() action. Sets are useful for set operations > > (union, intersection), but are not really helpful when it comes to > > incrementally construct them. When I need performance for such kind of > > lookups, a simple dictionary is usually way faster than sets :) I > > would suggest using a dictionary here :) > > 'set' is implemented as a 'dict', using add() method you just are adding > a new keyword, so using directly a 'dict' should be theorically faster. > Unfortunately, I cannot see this in a test I have executed (1,23% > slower). I'll try to run it again later. Maybe I miss something. > > Yes, after Russell's message, I double-checked set.add vs dict.__setitem__ performance, and to my surprise, the runtime differences where not as significant as I first thought. One important parameter however, seems to be the length of the keys.
I am currently running more systematic tests, I will let you know the results =) -- Nicolas Dumazet — NicDumZ [ nɪk.d̪ymz ]
_______________________________________________ Pywikipedia-l mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
