[New-bugs-announce] [issue37131] all(range()...)) is needlessley slow
Terji
report at bugs.python.org
Sun Jun 2 05:39:49 EDT 2019
New submission from Terji <Terji78 at yahoo.com>:
Checking if a range's items are ll truthy can be done y checking if 0 the range contains 0, however currently Python iterates over the range, making the operation slower than needed.
>>> rng = range(1, 1_000_000)
>>> timeit all(rng)
19.9 ms ± 599 µs per loop
If the all function could special case range, this could be like made fast like this:
if isinstance(obj, range):
if 0 in obj:
return False
return True
----------
components: Interpreter Core
messages: 344263
nosy: Petersen
priority: normal
severity: normal
status: open
title: all(range()...)) is needlessley slow
type: performance
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37131>
_______________________________________
More information about the New-bugs-announce
mailing list