Created
October 2, 2012 22:25
-
-
Save smetj/3823716 to your computer and use it in GitHub Desktop.
Check speed of dict lookups with 10000000 iterations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/smetj/experiments/blob/master/python/testlap/dict_eval.py | |
[smetj@indigo python]$ python speed_test_dict_eval.py | |
Running test_1 | |
OK | |
Running test_2 | |
OK | |
Running test_3 | |
OK | |
Running test_4 | |
OK | |
Running test_5 | |
OK | |
Running test_6 | |
OK | |
Running test_7 | |
OK | |
2.7.3 (default, Jul 24 2012, 10:05:38) | |
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] | |
Linux-3.5.4-2.fc17.x86_64-x86_64-with-fedora-17-Beefy_Miracle | |
Verify an existing key in a dictionary. | |
+----------+--------------------------------------------------------------------------+--------+---------------+ | |
| Function | Description | Result | Seconds | | |
+----------+--------------------------------------------------------------------------+--------+---------------+ | |
| test_6 | Check if an existing key exists in dictionary using in syntax. | OK | 2.0268681049 | | |
| test_7 | Check if a non existing key exists in dictionary using in syntax. | OK | 2.0622739792 | | |
| test_3 | Check if an existing key exists in dictionary using try except. | OK | 2.0864989758 | | |
| test_1 | Check if an existing key exists in dictionary using has_key. | OK | 2.7304418087 | | |
| test_2 | Check if an non existing key exists in dictionary using has_key. | OK | 2.8175299168 | | |
| test_4 | Check if a non existing key exists in dictionary using try except. | OK | 14.9449291229 | | |
| test_5 | Check if an existing key exists in dictionary using try except KeyError. | OK | 18.0724489689 | | |
+----------+--------------------------------------------------------------------------+--------+---------------+ | |
[smetj@indigo python]$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment