in reply to Re^2: Read Bit String...!!!
in thread Read Bit String...!!!
Dropping to C is indeed an option, but bit twiddling should be pretty darn fast in Perl too. To generate 1 million random numbers and process their bits took 4 seconds:
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 bi +ts\n");
4 seconds to count the 14665902 1s in 32_000_000 bits
Update: Oops! if $i>>=2; should be if ($i>>=2) & 1; as per reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Read Bit String...!!!
by ysth (Canon) on Apr 10, 2008 at 04:24 UTC |