#big-integer #bignum #benchmark

app bigint-benchmark

Benchmarks for big integer implementations

6 releases (3 breaking)

0.4.0 Sep 21, 2023
0.3.0 Oct 24, 2022
0.2.2 Jun 9, 2022
0.2.1 Nov 3, 2021
0.1.0 Mar 12, 2021

#1509 in Math

MIT and LGPL-3.0-only

17KB
298 lines

bigint-benchmark-rs

Benchmarks for Rust big integer implementations.

Each benchmark is run 5 times, with the calculation repeated for at least 10 seconds each time. The fastest attempt is used as the result.

Libraries

Library Version License Notes
rug 1.22.0 LGPL 3.0 Links to GMP
malachite 0.4.0 LGPL 3.0 Pure Rust, derived from GMP and FLINT
dashu 0.4.0 MIT or Apache 2.0 Fork of ibig. Pure Rust, no_std
ibig 0.3.6 MIT or Apache 2.0 Pure Rust, no_std
num-bigint 0.4.4 MIT or Apache 2.0 Pure Rust, no_std

Results

Library e 100k e 1m e 10m fib 10m fib 100m fib_hex 100m
rug 0.014 0.257 4.270 0.287 4.952 0.876
malachite 0.043 0.927 15.770 1.192 21.461 3.349
dashu 0.029 0.936 29.731 1.157 39.093 8.270
ibig 0.032 1.026 32.526 1.252 42.055 8.732
num-bigint 0.083 6.735 642.791 9.810 924.154 9.042

Times in seconds.

Usage

Calculate 100 digits of e and compare answers:

$ bigint-benchmark --task e --lib ibig --lib num-bigint --lib rug --lib malachite --lib dashu -n 100 print                                             
answer = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427
ibig       agrees
num-bigint agrees
rug        agrees
malachite  agrees
dashu      agrees

Calculate the 500-th Fibonacci number and compare answers:

$ bigint-benchmark --task fib --lib ibig --lib num-bigint --lib rug --lib malachite --lib dashu -n 500 print                                            
answer = 139423224561697880139724382870407283950070256587697307264108962948325571622863290691557658876222521294125
ibig       agrees
num-bigint agrees
rug        agrees
malachite  agrees
dashu      agrees

Benchmark calculating a million digits of e:

$ bigint-benchmark --task e --lib ibig --lib num-bigint --lib rug --lib malachite --lib dashu -n 1000000 benchmark

Tasks

Task Description Difficulty Algorithm Operations
e n digits of e Hard Binary splitting addition, multiplication, division, exponentiation, base conversion
fib n-th Fibonnaci number Medium Matrix exponentiation addition, multiplication, base conversion
fib_hex n-th Fibonnaci number in hex Easy Matrix exponentiation addition, multiplication

Dependencies

~13MB
~230K SLoC