- or download this
use strict;
use warnings;
...
Two => sub { popcount2($_) for $start .. $end },
Three => sub { popcount3($_) for $start .. $end },
};
- or download this
sanity test for correctness
Benchmark: timing 50 iterations of One, Three, Two...
One: 29 wallclock secs (28.41 usr + 0.00 sys = 28.41 CPU) @ 1.76/
+s (n=50)
Three: 10 wallclock secs (10.00 usr + 0.00 sys = 10.00 CPU) @ 5.00/
+s (n=50)
Two: 10 wallclock secs (10.03 usr + 0.00 sys = 10.03 CPU) @ 4.98/
+s (n=50)
- or download this
// Make GCC __builtin_popcountll available with MSVC
// (used to calculate the Hamming weight efficiently)
...
#define __builtin_popcountll __popcnt64
#define __builtin_popcount __popcnt
#endif
- or download this
# $cnt += popcount($row->[$iy] & $BM_MIDDLE);
$cnt += sprintf('%b', $row->[$iy] & $BM_MIDDLE) =~ tr/1//;