Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up str(int) #6202

Merged
merged 2 commits into from
Sep 24, 2020
Merged

Speed up str(int) #6202

merged 2 commits into from
Sep 24, 2020

Conversation

stuartarchibald
Copy link
Contributor

As title.

Fixes #6189

@stuartarchibald
Copy link
Contributor Author

Tested speed with:

from numba import njit
import time

@njit
def foo(n):
    c = 0
    for i in range(n):
        c += len(str(n))
    return c

def test(f):
    N = 10
    f(1)
    ts = time.time()
    for i in range(N):
        f(1000_000 + i)
    te = time.time()
    print("Elapsed = %s" % (te - ts))

test(foo.py_func)
test(foo)

This implementation seems at least twice as fast as cpython.

@stuartarchibald stuartarchibald added this to the Numba 0.52 RC milestone Sep 1, 2020
@stuartarchibald stuartarchibald added 3 - Ready for Review needs initial review This PR needs an initial review to check the code change is well formed, documented, efficient etc. and removed 2 - In Progress labels Sep 2, 2020
@stuartarchibald stuartarchibald added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 3 - Ready for Review needs initial review This PR needs an initial review to check the code change is well formed, documented, efficient etc. labels Sep 2, 2020
Copy link
Member

@esc esc left a comment

Choose a reason for hiding this comment

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

I tried this locally and it does accelerate things quite a bit:

Before

 💣 zsh» python issue6202.py
Elapsed = 1.975172758102417
Elapsed = 20.156193017959595

After:

 💣 zsh» python issue6202.py
Elapsed = 2.0004079341888428
Elapsed = 0.9646546840667725

@stuartarchibald
Copy link
Contributor Author

@esc is this ready to merge?

@esc esc added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Sep 24, 2020
@esc
Copy link
Member

esc commented Sep 24, 2020

@stuartarchibald it sure is! I have updated the label accordingly.

@sklam sklam merged commit cb7fb76 into numba:master Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integer to string conversion is extremely slow
4 participants