GMP with small numbers
Décio Luiz Gazzoni Filho
decio at decpp.net
Sun Jun 18 15:58:11 CEST 2006
On Jun 18, 2006, at 8:48 AM, Degski wrote:
> On 6/18/06, Paulo J. Matos <pocmatos at gmail.com> wrote:
>> Yes, It seems you're right. Well, less work for me... just need to
>> learn GMP, then! :-)
>> By the way, since I'm programming in C++ I'm considering to use GMP
>> C++ interface. Is there any kind of efficiency issue by using the
>> interface instead of the C functions directly, i.e., is it known
>> to be
> Well, since the C++ inteface is a wrapper around the C source, it's
> hard to imagine it would get any faster, and it's equally hard to
> imagine that you're not losing any speed in any part of the code, but
> I'm just guessing here.
> another clue of course is that GMP is written 99.9% in C. I don't know
> that much about C++, so I wouldn't like to comment on all the
> additional contructs available in C++. But f.e. overloading, which
> although very satisfying from a development point of view (in C you
> would write several different functions to cater for the different
> interfaces), could (not saying allways) lead to unnecessary function
> overhead, in other cases it probably makes no difference whatsoever,
> since in C you'll also need to decide upon (i.e. insert code), which
> funtion to use.
The C++ code uses expression templates, so that overloaded operators
are resolved to GMP functions at compile time with no runtime
overhead. Performance is indistinguishable from the C interface's
Anyway, the point of expression templates is to avoid unnecessary
temporaries -- function calls will happen anyway, whether to the
native C GMP calls or the overloaded operators, it's a function call
all the same. The only possible worry is in regard to unnecessary
temporary creation, and expression templates take care of that. You
might have a point if you use derived classes and virtual function
calls, but I don't think anyone is going to derive classes from GMP.
To the OP: you can use the C++ without any fear of performance loss.
Don't be afraid of C++ naysayers (in general, not only those that
spread misinformation about GMP's interface), they've long been wrong
about the performance of C++.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://gmplib.org/list-archives/gmp-discuss/attachments/20060618/d25d81ce/PGP.bin
More information about the gmp-discuss