Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make an O(1) fastpath for sum(range(...)) #107868

Closed as not planned
Closed as not planned
@mcognetta

Description

@mcognetta

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.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions