New submission from Serhiy Storchaka:

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

----------
components: Interpreter Core
files: set_faster_lookup.patch
keywords: patch
messages: 234367
nosy: pitrou, rhettinger, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Slightly faster set lookup
type: performance
versions: Python 3.5
Added file: http://bugs.python.org/file37789/set_faster_lookup.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23282>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to