April 30, 2004
test long Arithmetic result is:
in D, 155744 ms
but C,  33388 ms

why so much different? int and double type Arithmetic result is similrar. thanks.

test code D.ver is:
//from /* All code Copyright 2004 Christopher W. Cowell-Shah */
import std.math;
import std.date;

int main()
{
long longMin = 10000000000; // 10B
long longMax = 11000000000; // 11B

longArithmetic(longMin, longMax);

return 0;
}

double longArithmetic(long longMin, long longMax)
{
d_time startTime = getUTCtime();

long longResult = longMin;
long i = longMin;
while (i < longMax)
{
longResult -= i++;
longResult += i++;
longResult *= i++;
longResult /= i++;
}

d_time stopTime = getUTCtime();
double elapsedTime = (stopTime - startTime) / (TicksPerSecond / (double)
1000.0);
printf("Long arithmetic elapsed time: %1.0f ms with longMax %lld\n",
elapsedTime, longMax);
printf(" i: %lld\n", i);
printf(" longResult: %lld\n", longResult);
return elapsedTime;
}

C code is:
double longArithmetic(long long longMin, long long longMax)
{
double elapsedTime;
clock_t stopTime;
clock_t startTime = clock();

long long longResult = longMin;
long long i = longMin;
while (i < longMax)
{
longResult -= i++;
longResult += i++;
longResult *= i++;
longResult /= i++;
}

stopTime = clock();
elapsedTime = (stopTime - startTime) / (CLOCKS_PER_SEC / (double) 1000.0);
printf("Long arithmetic elapsed time: %1.0f ms with longMax %I64d\n",
elapsedTime, longMax);
printf(" i: %I64d\n", i);
printf(" longResult: %I64d\n", longResult);
return elapsedTime;
}


April 30, 2004
Against what compiler did you test? It has already been reported that DigitalMars compilers back-end are somewhat weakish in performance with respect to 64-bit integers.

I you should get roughly the same result comparing DigitalMars D compiler against DigitalMars C compiler.

Now there is also a new Gnu D compiler, giving you the ability to compare against GCC. However, if it scores good - wonderful. If it doesn't - no reason to worry, it has only been released a few weeks ago and has a chance to improve.

-eye

Gang Sung Jin schrieb:
> test long Arithmetic result is:
> in D, 155744 ms
> but C,  33388 ms
> 
> why so much different? int and double type Arithmetic result is similrar.
> thanks.
> 
> test code D.ver is:
> //from /* All code Copyright 2004 Christopher W. Cowell-Shah */
> import std.math;
> import std.date;
> 
> int main()
> {
> long longMin = 10000000000; // 10B
> long longMax = 11000000000; // 11B
> 
> longArithmetic(longMin, longMax);
> 
> return 0;
> }
> 
> double longArithmetic(long longMin, long longMax)
> {
> d_time startTime = getUTCtime();
> 
> long longResult = longMin;
> long i = longMin;
> while (i < longMax)
> {
> longResult -= i++;
> longResult += i++;
> longResult *= i++;
> longResult /= i++;
> }
> 
> d_time stopTime = getUTCtime();
> double elapsedTime = (stopTime - startTime) / (TicksPerSecond / (double)
> 1000.0);
> printf("Long arithmetic elapsed time: %1.0f ms with longMax %lld\n",
> elapsedTime, longMax);
> printf(" i: %lld\n", i);
> printf(" longResult: %lld\n", longResult);
> return elapsedTime;
> }
> 
> C code is:
> double longArithmetic(long long longMin, long long longMax)
> {
> double elapsedTime;
> clock_t stopTime;
> clock_t startTime = clock();
> 
> long long longResult = longMin;
> long long i = longMin;
> while (i < longMax)
> {
> longResult -= i++;
> longResult += i++;
> longResult *= i++;
> longResult /= i++;
> }
> 
> stopTime = clock();
> elapsedTime = (stopTime - startTime) / (CLOCKS_PER_SEC / (double) 1000.0);
> printf("Long arithmetic elapsed time: %1.0f ms with longMax %I64d\n",
> elapsedTime, longMax);
> printf(" i: %I64d\n", i);
> printf(" longResult: %I64d\n", longResult);
> return elapsedTime;
> }
> 
>