Table lookups - this is pretty definitive
Alix Pexton via Digitalmars-d
digitalmars-d at puremagic.com
Fri Apr 18 01:32:11 PDT 2014
I tested this against the others...
(with "-inline -release -O" of course)
===
uint[8] tab4; // bitop function only work on uints
static this()
{
for (size_t u = 0; u < 0x100; ++u)
{
if (isIdentifierChar0(cast(ubyte)u))
{
bts(tab4.ptr, u);
}
}
}
bool isIdentifierChar4(ubyte c)
{
return bt(tab4.ptr, c) != 0;
}
===
it takes about 3 times as long (about the same as the original
isIdentifierChar1, that used lots of &&s and ||s).
So 2 shifts, 2 ands and a compare to zero, beats core.bitop.
for clarity, the output of my benchmark for all 5 version was
Milliseconds 21 15 2 5 15
the 2 (which on some runs was a 3) is Walter's table of bools, the 5 is
my table of ulongs and the 15 on the end is core.bitop.
Short of delving into the asm, which I'm trying to avoid, any other
suggestions for speed-ups?
A...
More information about the Digitalmars-d
mailing list