Am 16.01.2007 um 10:46 schrieb Gustaf Neumann:
This is most probably the best variabt so far, and not complicated,
such a
optimizer can do "the right thing" easily. sorry for the many
versions..
-gustaf
{ unsigned register int s = (size-1) >> 3;
while (s>1) { s >>= 1; bucket++; }
}
if (bucket > NBUCKETS) {
bucket = NBUCKETS;
}
You'd be surprised that this one
s = (size-1) >> 4;
while (s > 0xFF) {
s = s >> 5;
bucket += 5;
}
while (s > 0x0F) {
s = s >> 4;
bucket += 4;
}
...
gives:
Test Tcl allocator with 4 threads, 16000 records ...
This allocator achieves 10098495 ops/sec under 4 threads
Press return to exit (observe the current memory footprint!)
whereas this one:
s = (size-1) >> 3;
while (s>1) { s >>= 1; bucket++;}
gives:
Test Tcl allocator with 4 threads, 16000 records ...
This allocator achieves 9720847 ops/sec under 4 threads
Press return to exit (observe the current memory footprint!)
That is (10098495-9720847/10098495)*100 = 3% less
That is all measured on Linux. I haven't done it on the Mac
and on the Sun yet. I now have all versions inside and will
play a little on each plaform to see which one operates best
overall. The latest one is more appealing because of the
siplicitly of the code, so we can close an eye on that 3%
I guess.
Cheers
Zoran