Compiler optimizations

pmoore pmoore_member at pathlink.com
Thu May 4 05:29:05 PDT 2006


I think I remember you posting a while ago that you have quite an old machine :)

In article <e3bdub$1dsu$3 at digitaldaemon.com>, Walter Bright says...
>
>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