How the speed of ER2 changes, run after run, against Python, SymPy and PARI. Drawn from every recorded run (make bench-record); the goal is ER2 faster than Python and not much slower than PARI/GP.
ER2 performance history
Generated by uv run python benchmarks/history.py from the runs in benchmarks/history/ (make bench-record adds one); do not edit by hand.
Each graph shows, run after run, how long ER2 takes compared with its reference (Python, fractions, SymPy or PARI through cypari2): below the dashed line ER2 is faster. The goal is ER2 faster than Python and not much slower than PARI/GP. Ratios are compared, not times, so runs on the same machine are comparable and the noise of a single run shows as small wiggles.
Runs: 2026-11-25 b44083f (main, baseline, before the improvements); 2026-11-25 dff4757 (main, rational + - * / fast path (c64f3f8)); 2026-11-26 4c333a4 (perf/plain-int, D22: plain int, exact / and ** (perf/plain-int)); 2026-11-26 a1fd279 (main, factor mod p once per call; faster start); 2026-11-26 c362f30 (main, D23 integer matrices as GP text; empty kernel); 2026-11-26 304cb29 (main, polynomials read from their terms; conversions group; matrices back from text); 2026-11-26 e7c4ba9 (main, kernel echelon, rationals inline, startup without typing, PARI on first use (D24)); 2026-11-28 699f0d3 (main, kernel, rationals, startup, error messages).
Startup
er2 startup, number theory only · vs Python |
×6.32 |
×3.67 |
×0.58 |
er2 startup, with symbols (loads SymPy) · vs Python |
×21.16 |
×19.77 |
×0.93 |
er2 startup, integers and rationals only · vs Python |
— |
×2.63 |
— |
Dispatch overhead (§2.1)
| choose a backend: phi(n), an integer · vs the whole call |
×0.055 |
×0.057 |
×1.04 |
| choose a backend: det, 10x10 over Z · vs the whole call |
×0.013 |
×0.019 |
×1.41 |
| choose a backend: det, 10x10 with a symbol · vs the whole call |
×0.000040 |
×0.000040 |
×1.00 |
| choose a backend: factor, a polynomial over Q · vs the whole call |
×0.11 |
×0.13 |
×1.13 |
Integer arithmetic (D2)
numeric loop, 20000 iterations (ER2 literals) · vs Python int |
×13.93 |
×1.00 |
×0.072 |
a + b · vs int a + b |
×8.25 |
— |
— |
a + b in an ER2 function · vs the same Python function |
— |
×1.51 |
— |
Integer(a) + Integer(b), the explicit class · vs int a + b |
— |
×4.10 |
— |
Exact rationals and large integers
a + b, rationals · vs fractions.Fraction |
×2.80 |
×1.21 |
×0.43 |
a * b / (a - b), rationals · vs fractions.Fraction |
×2.66 |
×1.16 |
×0.44 |
3^20000 * 3^20000, large integers · vs int |
×1.01 |
×1.05 |
×1.05 |
Number theory
| phi(n), n ≈ 1.2e8 · vs cypari2 |
×1.78 |
×1.81 |
×1.02 |
| phi(n), n ≈ 1.2e8 · vs SymPy |
×0.061 |
×0.057 |
×0.94 |
| sigma(n), n ≈ 1.2e8 · vs cypari2 |
×1.77 |
×1.75 |
×0.99 |
| sigma(n), n ≈ 1.2e8 · vs SymPy |
×0.061 |
×0.059 |
×0.97 |
| isprime(2^127 - 1), proven · vs cypari2 |
×1.02 |
×0.98 |
×0.97 |
| ispseudoprime (BPSW), Mersenne primes · vs cypari2 |
×1.15 |
×1.07 |
×0.93 |
| ispseudoprime (BPSW), Mersenne primes · vs SymPy |
×0.32 |
×0.30 |
×0.92 |
| factor(n), n ≈ 1e18 semiprime · vs cypari2 |
×1.08 |
×0.94 |
×0.87 |
| factor(n), n ≈ 1e18 semiprime · vs SymPy |
×0.019 |
×0.015 |
×0.81 |
Polynomial factorization
factor, degree 4 · vs SymPy factor |
×0.47 |
×0.35 |
×0.73 |
factor, degree 9 · vs SymPy factor |
×0.33 |
×0.25 |
×0.76 |
factor, degree 22 · vs SymPy factor |
×0.16 |
×0.17 |
×1.11 |
factor, degree 60 · vs SymPy factor |
×0.040 |
×0.035 |
×0.88 |
Polynomials over F_p (M5)
| factor mod 7, degree 12 · vs cypari2 |
×48.88 |
×14.30 |
×0.29 |
| factor mod 7, degree 12 · vs SymPy |
×0.37 |
×0.10 |
×0.28 |
| factor mod 7, degree 48 · vs cypari2 |
×4.95 |
×2.43 |
×0.49 |
| factor mod 7, degree 48 · vs SymPy |
×0.16 |
×0.074 |
×0.46 |
Linear algebra (M5)
| det, 10x10 over Z · vs cypari2 |
×8.36 |
×7.05 |
×0.84 |
| det, 10x10 over Z · vs SymPy |
×0.022 |
×0.016 |
×0.74 |
| kernel, 10x10 over Z · vs cypari2 |
×16.33 |
×7.26 |
×0.44 |
| kernel, 10x10 over Z · vs SymPy |
×0.41 |
×0.25 |
×0.62 |
| hermite_form, 10x10 over Z · vs cypari2 |
×7.97 |
×4.81 |
×0.60 |
| hermite_form, 10x10 over Z · vs SymPy |
×0.74 |
×0.49 |
×0.66 |
| smith_form, 10x10 over Z · vs cypari2 |
×4.70 |
×3.77 |
×0.80 |
| smith_form, 10x10 over Z · vs SymPy |
×0.34 |
×0.25 |
×0.74 |
| det, 20x20 over Z · vs cypari2 |
×3.52 |
×2.86 |
×0.81 |
| det, 20x20 over Z · vs SymPy |
×0.013 |
×0.0087 |
×0.65 |
| kernel, 20x20 over Z · vs cypari2 |
×3.64 |
×2.88 |
×0.79 |
| kernel, 20x20 over Z · vs SymPy |
×0.30 |
×0.21 |
×0.68 |
| hermite_form, 20x20 over Z · vs cypari2 |
×4.23 |
×2.66 |
×0.63 |
| hermite_form, 20x20 over Z · vs SymPy |
×0.34 |
×0.21 |
×0.61 |
| smith_form, 20x20 over Z · vs cypari2 |
×2.10 |
×1.85 |
×0.88 |
| smith_form, 20x20 over Z · vs SymPy |
×0.30 |
×0.33 |
×1.11 |
Calculus and series
expand((x + k)^20) · vs SymPy expand |
×1.00 |
×0.87 |
×0.87 |
diff, 5th derivative of x^k e^x sin(x) · vs SymPy diff |
×1.00 |
×0.98 |
×0.99 |
integrate x^k e^x · vs SymPy integrate |
×1.00 |
×1.01 |
×1.01 |
series of sin(x) e^(kx), order 10 · vs SymPy series |
×1.00 |
×1.12 |
×1.12 |
limit of (sin(kx) - kx) / x^3 at 0 · vs SymPy limit |
×1.01 |
×1.00 |
×1.00 |
Conversions SymPy <-> PARI (§2.1)
SymPy to PARI, 10x10 integer matrix · vs PARI matdet on it |
— |
×3.69 |
— |
PARI to SymPy, 10x10 integer matrix · vs PARI mathnf that made it |
— |
×1.65 |
— |
SymPy to PARI, 20x20 integer matrix · vs PARI matdet on it |
— |
×1.43 |
— |
PARI to SymPy, 20x20 integer matrix · vs PARI mathnf that made it |
— |
×0.53 |
— |
SymPy to PARI, polynomial of degree 12 · vs PARI factormod mod 7 on it |
— |
×4.17 |
— |
SymPy to PARI, polynomial of degree 48 · vs PARI factormod mod 7 on it |
— |
×0.29 |
— |