[New-bugs-announce] [issue4790] Optimization to heapq module
Nilton
report at bugs.python.org
Wed Dec 31 02:07:20 CET 2008
New submission from Nilton <nilton at google.com>:
The wrapper around heapq.nlargest and heapq.nsmallest is much slower
than it's C version.
$ python2.5 -mtimeit -s 'import random; random.seed(123); n=999999;
x=range(n); random.shuffle(x); import _heapq' '_heapq.nlargest(3, x)'
10 loops, best of 3: 142 msec per loop
$ python2.5 -mtimeit -s 'import random; random.seed(123); n=999999;
x=range(n); random.shuffle(x); import heapq' 'heapq.nlargest(3, x)'
10 loops, best of 3: 685 msec per loop
If the key argument is None, there is no need to use the wrapper. This
patch adds an a check to avoid this.
----------
components: Library (Lib)
files: heapq_optimization.diff
keywords: patch
messages: 78584
nosy: nilton
severity: normal
status: open
title: Optimization to heapq module
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.0, Python 3.1
Added file: http://bugs.python.org/file12501/heapq_optimization.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4790>
_______________________________________
More information about the New-bugs-announce
mailing list