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

Make as a C module (with Cython) #10

Open
suminb opened this issue Jun 28, 2017 · 2 comments
Open

Make as a C module (with Cython) #10

suminb opened this issue Jun 28, 2017 · 2 comments

Comments

@suminb
Copy link
Owner

suminb commented Jun 28, 2017

Our preliminary test shows promising results. Building base62 with Cython results in great improvement in performance.

Test code

import random

import base62


for _ in range(1000000):
    value = random.randint(0, 0xffffffff) 
    encoded = base62.encode(value)
    assert base62.decode(encoded) == value

Test with native Python (3.5)

(pybase62) ➜  base62 git:(develop) ✗ time python test.py
python test.py  8.41s user 0.00s system 99% cpu 8.420 total

Test with Cython

(pybase62) ➜  base62 git:(develop) ✗ time python test.py
python test.py  6.63s user 0.00s system 99% cpu 6.636 total

That's approximately 21% of speed improvement. More thorough tests shall be conducted in the near future.

@amcgregor
Copy link

For comparison, running on a 2.7GHz i7 MacBook Pro:

Python 3.6.2

# time python test.py
python tmp.py  9.79s user 0.03s system 99% cpu 9.835 total

PyPy 5.8.0 (≅ CPython 3.5.3)

# time pypy3 test.py
pypy3 tmp.py  2.52s user 0.04s system 82% cpu 3.116 total

@suminb
Copy link
Owner Author

suminb commented Sep 7, 2017

Thank you for your test results. PyPy is surely a better option for most cases. However, I'm using base62 for my work and we are unfortunately relying on some PyPy-incompatible packages :-(

I would recommend PyPy (or perhaps Pyston?) for anyone looking for performance improvement for base62.

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

No branches or pull requests

2 participants