[gambit-list] Bignum performance
lucier at math.purdue.edu
Thu Nov 3 17:46:10 EDT 2011
On Thu, 2011-11-03 at 16:11 -0400, Bradley Lucier wrote:
> Mikael sent me some comments about the bignum code, and he said it
> would be OK if I replied to the list.
> On Thu, 2011-11-03 at 18:34 +0200, Mikael wrote:
> > I saw the bignum benchmarks at
> > http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Benchmarks .
> > I'd suppose though that for small bignums (<2^512 or so), Gambit's
> > bignum handling is even so highly performant also compared with
> > using GMP, as Gambit has a deep bignum integration for instance with
> > partial inlining of operations and fast object handling.
I believe that the following are somewhat accurate comparisons of
Gambit's bignum multiplication with GMP's on my machine, which is
model name : Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz
running Ubuntu 11.10. I'm using the gmp binary compiled by the Ubuntu.
The top of the gmpbench output file is:
***** GMPbench version 0.2 *****
Using default CFLAGS = "-O3 -fomit-frame-pointer"
Using default CC = "gcc"
Using default LIBS = "-static -lgmp"
Using compilation command: gcc -O3 -fomit-frame-pointer foo.c -o foo
You may want to override CC, CFLAGS, and LIBS
Using gmp version: 5.0.1
Running benchmarks (propagated score accuracy exceeds printed
Program multiply (weight=1)
If multiply has only one argument, it means square a random integer with
that many bits. If it has two arguments, it means multiply two random
integers with that many bits. The number in the right column says how
many times that gmp can multiply two numbers of that size in one second.
So GMP can square a 128-bit number 4.785e+07 times in one second. The
last number is the geometric mean of the individual results.
I benchmarked (+ 1 2) through Gambit's trampoline and found that it can
be executed 24890460.8318176 times in one second, so GMP can square a
128-bit number faster than that!
The corresponding rates for Gambit's multiplication are
So for very large bignums, GMP is about twice as fast, and for small
bignums it is about 8 times as fast, as Gambit. Gambit has no special
code for taking advantage of the difference in size of the arguments.
The geometric average of the GMP rates is about 5.7 times as fast as
So I can think of some ways that I'd like to speed up Gambit, but it's
not going to be faster than GMP again at any operation (for a while it
was faster for large GCD).
More information about the Gambit-list