[Bf-committers] sqrt code snippet

Janek Kozicki bf-committers@blender.org
Sun, 30 May 2004 16:28:49 +0200


I wrote this piece of code to benchmark speed of sqrt(). I did it in
three minutes, so don't flame me for... umm? bad code ;)

Uncomment respective lines then compile.


#include <math.h>

main() 
{
//  float a,b,c,d;
//  double a,b,c,d;
  long double a,b,c,d;
  for(a=0.1;a<2000000;a+=0.1)
  {
//    b=sqrtf(a);
//    b=sqrt(a);
    b=sqrtl(a);

    // to fool compiler optimizations....
    // without this line a compiler may completely ignore above sqrt()
    c=b;d=c;b=d;
  }
};


I launched 'time test' several times, and averaged results for 
my PIII 600Mhz are:

float: 2.96s, double: 3.76s, long double 5.49s

I compiled with `g++ -o test test` if you want to ask why g++, then I
can answer only: I was in hurry :)

-- 
Janek Kozicki                                                         |