Message3971

Author pekka.klarck
Recipients pekka.klarck
Date 2008-12-19.22:17:53
SpamBayes Score 4.2162725e-08
Marked as misclassified No
Message-id <1229725074.91.0.411369776101.issue1212@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2008-12-19 22:17:55pekka.klarcksetrecipients: + pekka.klarck
2008-12-19 22:17:54pekka.klarcksetmessageid: <1229725074.91.0.411369776101.issue1212@psf.upfronthosting.co.za>
2008-12-19 22:17:54pekka.klarcklinkissue1212 messages
2008-12-19 22:17:54pekka.klarckcreate