my $stime = time; for (1..1_000_000) { my $i = rand(4294967295); while ($i) { $count++ if $i>>=2; } } my $etime = time; print($etime-$stime, " seconds to count the $count 1s in 32_000_000 bits\n"); #### $count += ($i > 2**2) + ($i > 2**4) + ($i > 2**6) + ... ($i > 2**26) + ($i > 2**28) + ($i > 2**30); #### do { ++$count if $i & 1; } while $i >>= 1;
## $count += ($i > 2**2) + ($i > 2**4) + ($i > 2**6) + ... ($i > 2**26) + ($i > 2**28) + ($i > 2**30); ##
## do { ++$count if $i & 1; } while $i >>= 1;