[issue13451] sched.py: speedup cancel() method

Giampaolo Rodola' report at bugs.python.org
Tue Nov 22 02:03:42 CET 2011


New submission from Giampaolo Rodola' <g.rodola at gmail.com>:

<snippet>
# bench.py
import sched, time
events = []
scheduler = sched.scheduler(time.time, time.sleep)
for x in range(4000):
    scheduler.enter(1, 1, lambda: None, ())
t = time.time()
for x in scheduler._queue:
    scheduler.cancel(x)
print(time.time() - t)
</snippet>

Before the patch:
9.433167934417725

After the patch:
1.3120810985565186


I have another approach in mind, which avoids removing the element from the queue immediately, and which should be an order of magnitude faster, but I'll provide that as a separate patch since it poses questions about API and backward compatibility.

----------
files: sched-cancel-speedup.patch
keywords: patch
messages: 148103
nosy: giampaolo.rodola, rhettinger, stutzbach
priority: normal
severity: normal
status: open
title: sched.py: speedup cancel() method
versions: Python 3.3
Added file: http://bugs.python.org/file23750/sched-cancel-speedup.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13451>
_______________________________________


More information about the Python-bugs-list mailing list