Message234367
Currently set_lookkey() first tests entry->key == NULL, then entry->hash == hash and entry->key != dummy, and only after that entry->key == key. Proposed patch optimizes the order of comparisons. entry->key == key is tested first as for dicts. And no need to test entry->key != dummy after entry->hash == hash if entry->hash of dummy key is set to -1.
Microbenchmark which demonstrates the best case (a lot of lookups of keys existing in the set).
$ ./python -m timeit -s "a = list(range(10**6)); s1 = set(a); s2 = set(a)" -- "s1 <= s2"
Unpatched: 10 loops, best of 3: 39.4 msec per loop
Patched: 10 loops, best of 3: 35.3 msec per loop |
|
Date |
User |
Action |
Args |
2015-01-20 10:39:16 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, pitrou |
2015-01-20 10:39:16 | serhiy.storchaka | set | messageid: <1421750356.2.0.166287277194.issue23282@psf.upfronthosting.co.za> |
2015-01-20 10:39:16 | serhiy.storchaka | link | issue23282 messages |
2015-01-20 10:39:16 | serhiy.storchaka | create | |
|