Reputation: 1773
I recently been doing some tasks for university, which include using Turbo Profiler (the software is implicitly declared in the task, sadly) for profiling C and Pascal implementations of Simpsons numerical integration. I came across very strange case, where Pascal is suspiciously much faster than C.
Pascal:
i: integer, lower: real, delta_x: real;
....
(0.0000 seconds) (30 times) x:=lower+delta_x*(2.0*i-1.0);
C:
long i, double lower, double delta_x;
....
(0.0549 seconds) (30 times) double x = lower + delta_x * (2.0 * i - 1.0);
So, what could it be, the difference between real
and double
(and integer
and long
) or just Pascal's compiler better at processing math operations?
Upvotes: 3
Views: 153
Reputation: 26361
The REAL of Pascal of Pascal is like FLOAT in C, an alias for the fastest floating point type on the given system.
So both fragments are not equivalent, in Pascal the most optimal type is used, and in C you hardcode double, the highest precision type (if we forget 80-bit floats)
In TP real default means an 48-bit soft floating point, but in many later programs {$N+} is added, which maps it onto x87 double.
I don't know Turbo C that well, but it could be that your (64-bit) double type is emulated (depending on settings), which would explain the performance degradation since obviously the emulation of a floating point value with more significant digits is slower. Or worse, you are benchmarking hardware FPU vs software somewhere.
Upvotes: 2
Reputation: 40689
Don't believe those numbers. If you want to measure time, put a loop of 10^6 or 10^9 iterations around the top subroutine, and count seconds. If you want to see what fraction of time goes into that statement, use stack-sampling.
Upvotes: 0