http://www.perlmonks.org?node_id=11113747


in reply to Re^3: Detecting whether UV fits into an NV
in thread Detecting whether UV fits into an NV

Moving the for loop into C space does enable the improvement in speed (about 12%) offered by uv_fits_double_ctz to become visible.

On my Windows 7 machine, perl-5.30.0, that improvement equates to the saving of 0.05 seconds in the processing of 12 million integer values.
That makes it somewhat less compelling, but a saving is a saving, and I would therefore be in favour of that approach, as opposed to the approach that I took.
I found that cutting the table size in half (by removing all zero entries) didn't measurably slow down uv_fits_double_ctz, in which we simply change the condition:
arg >>= ctz_table_11bit[arg & 2047]; to if(!(arg & 1)) arg >>= ctz_table_11bit[(arg & 2047) / 2];
I think I'd prefer using that reduced table (simply because it's half the size), though the altered line of code is perhaps not so readily intelligible.
The table could of course be further reduced in size, but I found that doing so started to impact on the performance.

Also note that uv_fits_double3 as presented here enters an infinite loop if given zero as an argument

Probably worth keeping in mind ;-)

I'll now take a look at the contribution provided by roboticus, as you've suggested.
I haven't had a chance to get to it earlier.

Thanks for the ideas and corrections !!

Cheers,
Rob