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

Use PEP 757 C-API to import/export integers #99

Merged
merged 1 commit into from
Dec 22, 2024

Conversation

skirpichev
Copy link
Member

Closes #14

@skirpichev
Copy link
Member Author

Benchmark export-ref export-patch
mpz(1<<7) 843 ns 400 ns: 2.11x faster
mpz(1<<38) 941 ns 395 ns: 2.38x faster
mpz(1<<300) 1.71 us 652 ns: 2.63x faster
mpz(1<<3000) 9.14 us 2.49 us: 3.66x faster
Geometric mean (ref) 2.64x faster
Benchmark import-ref import-patch
int(mpz(1<<7)) 681 ns 183 ns: 3.73x faster
int(mpz(1<<38)) 762 ns 222 ns: 3.43x faster
int(mpz(1<<300)) 1.54 us 554 ns: 2.78x faster
int(mpz(1<<3000)) 8.30 us 2.29 us: 3.63x faster
Geometric mean (ref) 3.37x faster
benchmarks code
# export-bench.py
import pyperf
from gmp import mpz


runner = pyperf.Runner()
ints = "1<<7", "1<<38", "1<<300", "1<<3000"

for v in ints:
    n = eval(v)
    v = "mpz(" + v + ")"
    runner.bench_func(v, mpz, n)
# import-bench.py
import pyperf
from gmp import mpz


runner = pyperf.Runner()
ints = "1<<7", "1<<38", "1<<300", "1<<3000"

for v in ints:
    n = mpz(eval(v))
    v = "int(mpz(" + v + "))"
    runner.bench_func(v, int, n)

@skirpichev skirpichev merged commit fbbf616 into diofant:master Dec 22, 2024
12 checks passed
@skirpichev skirpichev deleted the int-import/export branch December 22, 2024 07:45
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.

Fast mpz <-> int conversion
1 participant