I'll qualify this result to say
salva's result doesn't necessarily buy you anything if you are only doing this millions of times. On my machine, I get the timings
Generation took: 0.218580069542 seconds
Shift&and took: 0.000000471000 seconds
Lookup took: 0.000000395095 seconds
Where generation is calculated with
my $start = time;
for (1..100) {
my @lookup; $#lookup = 0x3ffff;
$lookup[ $_ ] = [ ( $_ & 0x3f000 ) >> 12, ( $_ & 0xfc0 ) >> 6, $_ & 0x
+3f ]
for 0 .. 0x3ffff;
}
printf "Generation took: %.12f seconds\n", ( time() - $start )/100;
I ran the transforms for 10^7 iterations, though frankly all metrics were still a little volatile for my taste. This puts breakeven at 2.9 million iterations and 5% speed up at 4.2 million. YMMV.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.