At 04:35 PM 10/23/05, Frank Bax wrote:

At 02:11 PM 10/23/05, John W. Krahn wrote:

Frank Bax wrote:
>         my $snew =
> sprintf("%4d%4d",$aSuit{$new}{'rescap'},$aSuit{$new}{'resval'});
>         my $slow =
> sprintf("%4d%4d",$aSuit{$low}{'rescap'},$aSuit{$low}{'resval'});

Using sprintf() to concatenate numbers is (AFAIK) going to be slower than
concatenation:

        my $snew = $aSuit{ $new }{ rescap } . $aSuit{ $new }{ resval };
        my $slow = $aSuit{ $low }{ rescap } . $aSuit{ $low }{ resval };

> my $aval=''; map { $aval=$aval.sprintf("%4d",$aSuit{$a}{$_}); } @f_seq; > my $bval=''; map { $bval=$bval.sprintf("%4d",$aSuit{$b}{$_}); } @f_seq;

You shouldn't use map in void context, you should use a foreach loop instead,
but you don't even need a loop there:

    my $aval = join '', @{ $aSuit{ $a } }{ @f_seq };
    my $bval = join '', @{ $aSuit{ $b } }{ @f_seq };


Your suggested code changes don't work when the list of numbers on each side of comparison have different number of digits - that's why I initially introduced sprintf - so all numbers would use 4 digits/characters. Concatenate 284 and 9 to get 2849, 284 and 10 to get 28410, which comes before 2849 in sting compare. Using sprintf("%4d",...) - " 284 9" is compared to " 284 10" and works properly in this context.


I just changed and tested:
my $aval=''; map { $aval=$aval.sprintf("%4d",$aSuit{$a}{$_}); } @f_seq; my $bval=''; map { $bval=$bval.sprintf("%4d",$aSuit{$b}{$_}); } @f_seq;
to:
my $aval=''; foreach $f (@f_seq) { $aval=$aval.sprintf("%4d",$aSuit{$a}{$f}); } my $bval=''; foreach $f (@f_seq) { $bval=$bval.sprintf("%4d",$aSuit{$b}{$f}); }

For my script "foreach" took 195 seconds, compared to 160 seconds using "map". We're headed in the wrong direction here!

FYI: I added a counter to cmpSuit function - it gets called 14.2 million times on our small test database.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to