Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Question on performance



Paul

As far as I can see in your example code, t never is NaN throughout the loop. Wouldn't it be useful to have tests where the other branch of "isnan (x) ? 0.0 : x" is taken (a) in a regular pattern, (b) in a random way? That would test, for instance, what effect the hardware's branch-prediction has on performance.

John

On 9 Oct 2010, at 10:36, Paul Zimmermann wrote:
> Arnold wrote:
>> I have a question about performance on current 754-conforming hardware:
>> 
>> Suppose I write code consisting only of 754 floating-point operations
>> and calls to simple customized additional functions such as
>>     nan2zero(x), which returns 0 if isnan(x), and x otherwise...
> 
> here is a test case....
> Paul Zimmermann
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h>
> 
> double
> nan2zero (double x)
> {
>  return isnan (x) ? 0.0 : x;
> }
> 
> int
> main()
> {
>  double t, s, i, N = 1000000000.0;
> 
>  /* compute s = sum(1/k!, k=0..N) */
>  for (t = 1.0, s = t, i = 1; i <= N; i++)
>    {
>      t /= i;
> #ifdef TEST
>      s += nan2zero (t);
> #else      
>      s += t;
> #endif
>    }
>  printf ("s=%.16e\n", s);
> }