Issue1212

classification
Title: 'x' in dictionary much slower than dictionary.has_key('x')
Type: Severity: normal
Components: Versions: 2.2.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: pekka.klarck, zyasoft
Priority: Keywords:

Created on 2008-12-19.22:17:54 by pekka.klarck, last changed 2008-12-27.20:24:38 by zyasoft.

Files
File name Uploaded Description Edit Remove
in_vs_haskey.py pekka.klarck, 2008-12-19.22:17:53 Example demonstrating the performance of 'in' and 'has_key'
Messages
msg3971 (view) Author: Pekka Klärck (pekka.klarck) Date: 2008-12-19.22:17:53
On Jython it is much faster to test is an item in a dictionary with
'has_key' method than using 'in' keyword. The latter is normally
preferred because it is more idiomatic Python and also faster on
CPython. The attached example demonstrates this problem. When I execute
it on my system I got following results.

$ jython --version && jython in_vs_haskey.py 
Jython 2.2 on java
has_key_test dict 0.7
in_test dict 1.573
has_key_test UserDict 1.224
in_test UserDict 2.313

$ python --version && python in_vs_haskey.py 
Python 2.5.1
has_key_test dict 0.243
in_test dict 0.146
has_key_test UserDict 0.504
in_test UserDict 0.529
msg3975 (view) Author: Jim Baker (zyasoft) Date: 2008-12-27.20:24:37
For Jython 2.5, it's faster to use the in operator instead of has_key.
(About 2x when run on my OS X box.) It's also just marginally slower
when running on Java 6 when compared to CPython, so that's pretty nice too.

We are very unlikely for us to consider improving performance for 2.2
with 2.5 to be released soon, so I'm marking this closed/won't fix.
History
Date User Action Args
2008-12-27 20:24:38zyasoftsetstatus: open -> closed
resolution: wont fix
messages: + msg3975
nosy: + zyasoft
versions: + 2.2.2
2008-12-19 22:17:54pekka.klarckcreate