Mail Archives: djgpp/1999/02/04/22:38:33
> PS: i hope nobody was compiling this code with optimisation on.
> when i do that everything is much MUCH faster and long and long-long
> ops take exactly the same amount of time. I assume this is becuz
> gcc see's the multiplications as useless, since we never use the
> values of foo and bar.
The way to avoid this is to define your benchmark function
as a global function that uses global variables, like this:
long a1, b1, c1, a2, b2, c2;
void benchmark()
{
a1 = b1 * c1;
a2 = b2 * c2;
}
Make sure your benchmark function is defined *after* your testing
function, so that it won't be inlined. You can write a similar
function that is exactly the same except that it does no multiplies,
and use that as a baseline to measure the overhead, which you then
subtract from your overall timings, leaving just the times for the
multiplies themselves.
Inline a whole bunch of multiplies, like 10 or 20, to reduce the
effects of the testing overhead (loops, function calls). Use a macro
to ease use, if you can figure out the ANSI string pasting syntax.
Another option is to use a loop that multiplies elements of two arrays
and stores in a third.
You *do* want to optimize when testing stuff like this. I suspect it
would make a big difference in the ratios.
Based on the code gcc is generating, I'd expect long long multiplies
to take a little more than three times longer than long multiplies,
since it's using three multiply opcodes and some adds.
- Raw text -