Skip to content

Optimize builtins/range#2460

Merged
coolreader18 merged 1 commit into
RustPython:masterfrom
pca006132:range-opt
Feb 15, 2021
Merged

Optimize builtins/range#2460
coolreader18 merged 1 commit into
RustPython:masterfrom
pca006132:range-opt

Conversation

@pca006132

Copy link
Copy Markdown
Contributor

This avoids unnecessary operations, such as clone, multiplication, and division.

For the following microbenchmark, the current master would take time 3.41s, 0.73s, 3.69s, and it takes 2.27s, 0.50s, 2.60s after applying this patch.

import time

t0 = time.time()
for i in range(10000000):
    pass
t1 = time.time()
print(t1 - t0)

t0 = time.time()
for i in range(0, 10000000, 5):
    pass
t1 = time.time()
print(t1 - t0)

t0 = time.time()
for i in range(10000000, 0, -1):
    pass
t1 = time.time()
print(t1 - t0)

Previously, the PyRange::get function takes 30% of the time, and it takes only 10% of execution time after this optimization.

Currently, 34% of the time is spent on PyDict::inner_itemset_fast (a lot of time spent on dropping the old value), and about 10% is spent on BigInt conversion from usize and to PyInt.

@coolreader18 coolreader18 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coolreader18 coolreader18 merged commit 820337e into RustPython:master Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants