Compiler optimizations

Craig Black cblack at ara.com
Sun Apr 30 12:34:27 PDT 2006


This is probably because you have SSE optimizations disabled.
This one works even without SSE.  This shows that integer division is
slower.  Also, if you change the division to multiplication, you will notice
that integer multiplication is faster, which is what you would expect.

#include <stdio.h>
#include <conio.h>
#include <time.h>

//typedef int divtype;
typedef double divtype; // This one is faster

int main()
{
   divtype result = 0;

   clock_t start, finish;
   double  duration;

   start = clock();
   divtype max = 100000000;
   for(divtype div=1; div<max; div++)
   {
     divtype i = max - div;
     result += i / div;
   }
   finish = clock();
   duration = (double)(finish - start) / CLOCKS_PER_SEC;

   printf("[%f] %2.1f seconds\n",double(result),duration);
}





More information about the Digitalmars-d mailing list