Skip to main content

Benchmarks

What ER2 costs against SymPy and against raw PARI. These record what is true today, not a promise (see Stability, N6).

ER2 benchmarks

Generated by uv run python benchmarks/run.py --write; do not edit by hand.

Python 3.14.6, SymPy 1.14.0, cypari2 2.2.4, x86_64. Times are medians per call; ×1.00 means ER2 is as fast as the reference.

Notes: isprime proves primality (PARI’s APRCL); sympy.isprime and ispseudoprime run the BPSW probable-prime test, so they are compared with each other. Number theory calls get a different argument each time, because SymPy caches results.

Startup

Benchmark ER2 Reference Reference time ER2 / reference
er2 startup, integers and rationals only 157 ms Python 28.5 ms ×5.49
er2 startup, number theory only 143 ms Python 28.5 ms ×4.99
er2 startup, with symbols (loads SymPy) 792 ms Python 28.5 ms ×27.74

Dispatch overhead (§2.1)

Benchmark ER2 Reference Reference time ER2 / reference
choose a backend: phi(n), an integer 569 ns the whole call 13.1 µs ×0.04
choose a backend: det, 10x10 over Z 2.55 µs the whole call 145 µs ×0.02
choose a backend: det, 10x10 with a symbol 1.34 ms the whole call 2.74 ms ×0.49
choose a backend: factor, a polynomial over Q 65.9 µs the whole call 500 µs ×0.13

Integer arithmetic (D2)

Benchmark ER2 Reference Reference time ER2 / reference
numeric loop, 20000 iterations (ER2 literals) 1.86 ms Python int 2.03 ms ×0.92
a + b in an ER2 function 98.7 ns the same Python function 106 ns ×0.93
Integer(a) + Integer(b), the explicit class 376 ns int a + b 104 ns ×3.62

Exact rationals and large integers

Benchmark ER2 Reference Reference time ER2 / reference
a + b, rationals 1.35 µs fractions.Fraction 770 ns ×1.75
a * b / (a - b), rationals 2.79 µs fractions.Fraction 2.49 µs ×1.12
3^20000 * 3^20000, large integers 339 µs int 397 µs ×0.85

Number theory

Benchmark ER2 Reference Reference time ER2 / reference
phi(n), n ≈ 1.2e8 12.2 µs cypari2 4.67 µs ×2.61
phi(n), n ≈ 1.2e8 12.2 µs SymPy 117 µs ×0.10
sigma(n), n ≈ 1.2e8 9.14 µs cypari2 3.82 µs ×2.39
sigma(n), n ≈ 1.2e8 9.14 µs SymPy 132 µs ×0.07
isprime(2^127 - 1), proven 466 µs cypari2 483 µs ×0.96
ispseudoprime (BPSW), Mersenne primes 37.7 µs cypari2 33.7 µs ×1.12
ispseudoprime (BPSW), Mersenne primes 37.7 µs SymPy 124 µs ×0.30
factor(n), n ≈ 1e18 semiprime 341 µs cypari2 279 µs ×1.22
factor(n), n ≈ 1e18 semiprime 341 µs SymPy 21.3 ms ×0.02

Polynomial factorization

Benchmark ER2 Reference Reference time ER2 / reference
factor, degree 4 506 µs SymPy factor 1.31 ms ×0.39
factor, degree 9 1.05 ms SymPy factor 4.01 ms ×0.26
factor, degree 22 2.38 ms SymPy factor 15 ms ×0.16
factor, degree 60 14.5 ms SymPy factor 452 ms ×0.03

Polynomials over F_p (M5)

Benchmark ER2 Reference Reference time ER2 / reference
factor mod 7, degree 12 450 µs cypari2 31.9 µs ×14.10
factor mod 7, degree 12 450 µs SymPy 5.61 ms ×0.08
factor mod 7, degree 48 2.38 ms cypari2 960 µs ×2.48
factor mod 7, degree 48 2.38 ms SymPy 35.3 ms ×0.07

Linear algebra (M5)

Benchmark ER2 Reference Reference time ER2 / reference
det, 10x10 over Z 138 µs cypari2 25.4 µs ×5.43
det, 10x10 over Z 138 µs SymPy 8.58 ms ×0.02
kernel, 10x10 over Z 387 µs cypari2 25.9 µs ×14.94
kernel, 10x10 over Z 387 µs SymPy 1.16 ms ×0.33
hermite_form, 10x10 over Z 301 µs cypari2 71 µs ×4.23
hermite_form, 10x10 over Z 301 µs SymPy 679 µs ×0.44
smith_form, 10x10 over Z 425 µs cypari2 107 µs ×3.95
smith_form, 10x10 over Z 425 µs SymPy 1.48 ms ×0.29
det, 20x20 over Z 714 µs cypari2 261 µs ×2.73
det, 20x20 over Z 714 µs SymPy 81.4 ms ×0.01
kernel, 20x20 over Z 1.35 ms cypari2 487 µs ×2.78
kernel, 20x20 over Z 1.35 ms SymPy 6.36 ms ×0.21
hermite_form, 20x20 over Z 1.21 ms cypari2 416 µs ×2.91
hermite_form, 20x20 over Z 1.21 ms SymPy 6.32 ms ×0.19
smith_form, 20x20 over Z 1.94 ms cypari2 1.19 ms ×1.63
smith_form, 20x20 over Z 1.94 ms SymPy 7 ms ×0.28

Calculus and series

Benchmark ER2 Reference Reference time ER2 / reference
expand((x + k)^20) 12.1 ms SymPy expand 12.1 ms ×1.00
diff, 5th derivative of x^k e^x sin(x) 61 ms SymPy diff 58 ms ×1.05
integrate x^k e^x 88.9 ms SymPy integrate 80.2 ms ×1.11
series of sin(x) e^(kx), order 10 206 ms SymPy series 191 ms ×1.08
limit of (sin(kx) - kx) / x^3 at 0 42.5 ms SymPy limit 40.5 ms ×1.05

Rational functions in PARI (D26, switch on)

Benchmark ER2 Reference Reference time ER2 / reference
f + g (rational functions in x, y) 21.6 µs SymPy cancel(f + g) 40.3 ms ×0.00
gcd of polynomials in x, y 91.1 µs SymPy gcd 16.9 ms ×0.01
factor of a polynomial in x, y 711 µs SymPy factor 30.7 ms ×0.02
resultant in x 49.9 µs SymPy resultant 31 ms ×0.00
diff of a rational function 25.6 µs SymPy diff + cancel 73.8 ms ×0.00
series of a rational function, order 20 476 µs SymPy series 258 ms ×0.00
solve, roots of degree <= 2 620 µs SymPy solve 53.4 ms ×0.01
collect by x 726 µs SymPy collect 17.7 ms ×0.04
solve(A, b), 3x3 polynomials in x, y 75.7 ms SymPy Matrix.solve 6.24 s ×0.01
det, 4x4 polynomials in x, y 12.1 ms SymPy det 1.04 s ×0.01

Elementary functions in PARI (D27, D28, switch on)

Benchmark ER2 Reference Reference time ER2 / reference
decide (sin x + cos x)^8 - (1 + sin 2x)^4 = 0 446 µs SymPy trigsimp 259 ms ×0.00
linearize and print sin^(k+2) x cos^2 x 2.06 ms SymPy fu (does not linearize) 49.6 ms ×0.04
diff of sin^(k+2) x cos^2 x 99.4 µs SymPy diff 18.8 ms ×0.01
integrate x^k sin^2 x cos x 544 µs SymPy integrate 989 ms ×0.00
decide cosh^2 x - sinh^2 x = 1 225 µs SymPy simplify 50.7 ms ×0.00
integrate x^k e^(-x) sin x 528 µs SymPy integrate 6.45 s ×0.00
series of tan x, order 12 1.14 ms SymPy series 29 ms ×0.04

Elliptic curves (D29)

Benchmark ER2 Reference Reference time ER2 / reference
torsion points of y^2 = x^3 + a x + b over Q 67.8 µs SymPy torsion_points 119 ms ×0.00
number of points over F_1009 41.9 µs SymPy order (enumeration) 776 ms ×0.00

Conversions SymPy <-> PARI (§2.1)

Benchmark ER2 Reference Reference time ER2 / reference
SymPy to PARI, 10x10 integer matrix 65.1 µs PARI matdet on it 15 µs ×4.33
PARI to SymPy, 10x10 integer matrix 49 µs PARI mathnf that made it 35.4 µs ×1.39
SymPy to PARI, 20x20 integer matrix 234 µs PARI matdet on it 155 µs ×1.50
PARI to SymPy, 20x20 integer matrix 113 µs PARI mathnf that made it 368 µs ×0.31
SymPy to PARI, polynomial of degree 12 146 µs PARI factormod mod 7 on it 31.4 µs ×4.64
SymPy to PARI, polynomial of degree 48 361 µs PARI factormod mod 7 on it 978 µs ×0.37