Closed as not planned
Description
Currently, sum(range(...))
falls back to an iterative loop that takes O(n)
time, where n
is the length of the range. Instead, this can be done in O(1)
time with some arithmetic.
This is slightly related to issue #68264, where it is noted that sum(range(...))
had a slightly performance regression between Python2 and 3. However, in both cases, an O(n)
time implementation is used.
Note: this is my first time contributing here using only Github. I already have a patch prepared, but I think I needed to open an issue first.