"slowness" (Jonathan Cook)

Jim White mathimagics at yahoo.co.uk
Tue Jan 22 02:17:46 CET 2008

> Date: Sat, 19 Jan 2008 00:04:50 +0000
> From: Jonathan Crook <je.suis.bon at googlemail.com>
> Subject: slowness
> Hi, I have been working on a mandelbrot fractal
> generator, and have decided to use GMP, to maintain 
> precision through extensive zooming.
> However, whereas a fractal would generate in <1s
> using long doubles, with mpf_class it takes around 
> 180s. I understand that in my code, this
> causes an incredible amount and frequency of
> function calls, and thus  also GMP arithmetic, but
> am I to expect this kind of performance
> overhead, or am I merely doing something wrong?
> Thanks, Jonny.
You certainly have to accept that multi-word
software-controlled arithmetic is inherently "slow"
compared to arithmetic with native data types.

The relative speed factor is of course largely
dependent on the size of the operands, and can also be
affected to various degrees by the efficiency of your
coding and usage of the GMP library.

You also need to understand that calculation times do
not grow linearly. For example, if you double the
precision of your floating-point operands,
multiplication costs will tend to rise by a factor of

You have not said what mpf precision you are working
with, but it should be clear that it does not take
many doublings of precision to get a cost factor of
180 relative to native arithmetic operations.


Jim White

More information about the gmp-discuss mailing list