Newbie: Need help for benchmarking multiplication between two Floating Points.

Andreas Andreakis andreas.andreakis at googlemail.com
Fri Dec 14 21:57:53 CET 2007


Sorry for posting two messages, but the last mail was not complete. Here is
whats missing:

I have the following problems with the current code:

1) if precision is set to 9999999 (7 nines) the multiplication needs
0.4seconds. However if I set the precision to 9999999 (7 nines) the
function
needs 5,4 seconds.
2) if I generate a number which is 100000 digits long, then the problem
crashes when it executes mpf_init_set_str(x, createStringDecimal(100000),
0);

However with 10000 digits it works fast and fine: mpf_init_set_str(x,
createStringDecimal(10000), 0);

what am I doing wrong ?
hope you can help.

also, how I measure the elapsed time in milliseconds ?


thank you in advance,
Andreas



On Dec 14, 2007 9:47 PM, Andreas Andreakis <andreas.andreakis at googlemail.com>
wrote:

> Hallo,
>
> I´m currently evaluating GMP against libraries from other languages (such
> as from java). I´ve already tried to write a program which multiplies two
> numbers, but I´m experiencing various problems. Also I´m not very
> experienced in C++, so I cant tell if its me if I´m using GMP wrong. Thus I
> need your help, in order to make sure that my function is written correctly
> and as efficient as possible.
>
> This are the conditions:
> 1) precision must be presetup and set to 999999999
> 2) generate a decimal from a string := number (I hava already the method
> which generates the string / const char)
> 3) calculate number*number
> 4) show elapsed time in milliseconds for that operation
>
> Here is my code (using C):
>
>
> int main() {
>
>     long precision = 9999999;
>
>     mpf_set_default_prec(precision);
>
>     mpf_t x, result;
>
>     mpf_init(result);
>
>     mpf_init_set_str(x, createStringDecimal(10000), 0);
>  //createStringDecimal is already implemented, it returns a floating point
> number of the given length
>
>     clock_t t1, t2;
>     t1 = clock();
>
>     //action
>     mpf_mul(result, x, x);
>
>     t2 = clock();
>     printf("\nFinished in %.2f seconds.\n\n", (t2-t1)*1.0/CLOCKS_PER_SEC);
>
>     int n = 1000;
>     gmp_printf ("fixed point mpf %.*Ff with %d digits\n", n, x, n);
>     gmp_printf ("fixed point mpf %.*Ff with %d digits\n", n, result, n);
>
>     return 0;
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gmplib.org/list-archives/gmp-discuss/attachments/20071214/362f2362/attachment.html 


More information about the gmp-discuss mailing list