This benchmarks as around %1500 quicker than the original.
s/iter org new best org 5.62 -- -78% -94% new 1.26 346% -- -73% best 0.345 1529% 266% -- The results are the same
It'll probably be deemed unreadble, but it is a bit quick.
sub ba2bi2 { my @ba = reverse (@_, (0) x (4 - ( @_%4 || 4 ) ) ); my $result = Math::BigInt->new(0); $result *= 4294967296 , $result += $_ for map{ unpack 'N' , pack 'C4' , @ba[4*$_ .. 4*$_+3] } 0 .. ($#ba/4); return $result; }
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
In reply to Re: Converting an array of bytes into a BigInt - 1500% quicker.
by BrowserUk
in thread Converting an array of bytes into a BigInt - speed considerations
by dempa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |