count of bits in a long
Tim W Smith
ts at cup.portal.com
Wed Oct 24 16:48:43 AEST 1990
When benchmarking something like this, a good thing to do
is to do a back-of-the-envelope estimate of what you
expect. For example, the Mac II runs at 16 MHz. Assume
a few wait states, and loop overhead, and stuff like that
will limit us to 1 "useful" instruction every 8 clocks,
so we get 2 "useful" MIPS. The operation x &= x-1 will
take three operations. At 2 MIPS, an operation is 1/2 uSec,
so we have 1.5 uSec per bit. The loop runs an average of
16 times, so we expect that we can do it in 24 uSec.
The measured time was something like 20 uSec, so we
pass.
If you see numbers in the hundreds of microseconds, you
can be almost sure that something is wrong with the program.
Tim Smith
More information about the Comp.lang.c
mailing list