Philippe Ranger wrote:
> > <<Bob: > Besides, it would seem that wrapping around the best of the > "bitsInByte" solutions would be both faster and less cumbersome. > >> > > Perhaps, but that involves one call per byte.
By wrap I meant put the code inside a loop. This is between 1.7 and 3x faster depending on the size of the set on a PII, and it uses your BitsInByte Nibble algorithm crushed into one pascal expression.
function card1(var tar; size: integer): integer; const nibbleTable:array[0..15] of integer=( 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4); var Data:PByteArray; i,b:integer; begin result:=0; Data:=@TByteArray(tar)[size]; i:=-size; while i<0 do begin b:=Data[i]; inc(result,NibbleTable[b and $F]+NibbleTable[(b shr 4) and $F]); inc(i); end; end;
-- Bob Lee High Performance Delphi - http://www.econos.com/optimize/ Updated August 2