Performance ordered dictionary vs normal dictionary
Raymond Hettinger
raymond.hettinger at gmail.com
Thu Jul 29 04:12:38 EDT 2010
On Jul 28, 6:47 pm, Navkirat Singh <navkir... at gmail.com> wrote:
> I was wondering what would be better to do some medium
> to heavy book keeping in memory - Ordered Dictionary
> or a plain simple Dictionary object??
The current implementation of OrderedDict is based on regular
dictionaries, so it performance cannot be better than a regular
dictionary for the usual mapping operations. Some accessor methods
like __getitem__(), __len__(), __contains__(), and get() are pass
throughs, so their performance is the same. Most of the rest of the
methods are order aware and are slower by a constant factor.
So, if you don't need the ordering feature, then you're better-off
with a regular dictionary.
A potential future implementation for OrderedDict written in C would
have nearly identical performance as regular dicts for most operations
and slightly improved performance for iteration.
Raymond
More information about the Python-list
mailing list