Mail Archives: djgpp-workers/2001/02/05/03:54:58
On Sun, 4 Feb 2001 lauras AT softhome DOT net wrote:
> Eli Zaretskii writes:
> > However, I didn't find any evidence that an int is faster than a char.
> > Can you provide such an evidence, e.g., by looking at the code produced
> > by gcc 2.9X and counting cycles?
>
> I tried. I was wrong - the difference between two versions is very little.
>
> Here is my "benchmark":
>
> int main(void)
> {
> unsigned char x, y, z, t, u, v;
> for (x = 0; x < 200; x++)
> for (y = 0; y < 200; y++)
> for (u = 0; u < 200; u++)
> for (v = 0; v < 200; v++)
> {
> z = x * y;
> t = z - x / y;
> z = t + u;
> t = z - u;
> }
> return 0;
> }
This program divides by zero (when y == 0), so its precise timing is
extremely system-dependent (on some systems, it crashes right away).
It also throws away the results of the computations, so a really smart
compiler could transform it into a no-op.
I modified the program as shown below (removing the unsigned qualifier
while I was at it, to let the compiler work with processor's native
data types), and the results on a P166 were:
int version: 41 seconds
short version: 45 seconds
char version: 36 seconds
int main(void)
{
char x, y, z, t, u, v;
for (x = 0; x < 100; x++)
for (y = 1; y < 101; y++)
for (u = 0; u < 100; u++)
for (v = 0; v < 100; v++)
{
z = x * y;
t = z - x / y;
z = t + u;
t = z - u;
}
return t;
}
- Raw text -