[EMAIL PROTECTED] wrote:
>
> A word on relative efficiencies of the two formulae listed below... I
> ran timethese/cmpthese on the two, using a half-million iterations, ten
> times. The "folded" formula came out faster six times, at an average of
> 8.67% faster, while the long form won the race four times, but with an
> average of 12.25% faster.
This would be even faster (assumes no numbers larger than 255) :
$sum = $A << 24 | $B << 16 | $C << 8 | $D;
> I leave it to the statisticians out there to sort out the meaning of
> these figures, and I've appended the script used for those interested in
> playing about any further.
>
>
> ********************************* code
> ***********************************
> #! /usr/local/bin/perl
>
> use strict;
> use warnings;
> use Benchmark qw(timethese cmpthese);
>
> my ($A, $B, $C, $D) = (10, 21, 11, 6);
> my $sum;
>
> my $r = timethese( 500_000, {
>
> 'long test' => sub {
>
> $sum = (256*256*256*$A) + (256*256*$B) + (256*$C) + $D;
> },
>
>
> 'short test' => sub {
>
> $sum = (($A*256+$B) * 256 + $C) * 256 + $D;
>
> }
>
> } );
>
> cmpthese( $r );
> ********************************* code
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs