[issue2607] why is (default)dict so slow on tuples???

Andreas Eisele report at bugs.python.org
Thu Apr 10 18:21:41 CEST 2008


New submission from Andreas Eisele <eisele at dfki.de>:

I need to count pairs of strings, and I use 
a defaultdict in a construct like

count[a,b] += 1

I am able to count 50K items per second on a very fast machine,
which is way too slow for my application.

If I count complete strings like

count[ab] += 1

it can count 500K items/second, which is more reasonable.

I don't see why there is a performance penalty of a factor
of 10 for such a simple construct.

Do I have to switch to Perl or C to get this done???

Thanks a lot for any insight on this.

Best regards,
Andreas

PS.: The problem seems to exist for ordinary
dicts as well, it is not related to the fact that
I use a defaultdict

PPS: I also tried nested defaultdicts
count[a][b] += 1
and get the same slow speed (and 50% more memory consumption)

----------
messages: 65293
nosy: eisele
severity: normal
status: open
title: why is (default)dict so slow on tuples???
type: performance
versions: Python 2.5

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2607>
__________________________________


More information about the Python-bugs-list mailing list