Compiler optimizations

Walter Bright newshound at digitalmars.com
Wed May 3 16:21:50 PDT 2006


On my machine, integer is still faster.

int: 3.7
double: 4.2

Craig Black wrote:
> 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