Dicts 5x Faster than Sets
aahz at pythoncraft.com
Thu Jun 10 22:53:07 CEST 2004
In article <889cbba0.0406091124.4c29126e at posting.google.com>,
Kamilche <klachemin at home.com> wrote:
>Hm, I just saw the 'sets' feature, and ran some timings to see if I
>should use it instead of 'dict' sometimes. I discovered it's 4x slower
>in adding, and 6x slower in removing items!
Speed is not the raison d'etre for sets, convenience and clarity are.
You are better off using sets if you need set intersection and union,
Keep in mind that dicts are probably the single most highly optimized
chunk of code in Python, and that sets are built on top of dicts.
Unless you need the absolute utmost in speed, the penalty you're paying
for the wrapper code shouldn't be an issue.
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"as long as we like the same operating system, things are cool." --piranha
More information about the Python-list