in reply to Re: Pls help optomize - ksh version 60% faster!
in thread Pls help optomize - ksh version 60% faster!

Question: instead of
push @rptType, $rptType unless @rptType; push @rptType, $rptType unless grep /$rptType/, @rptType;
I would use
push @rptType, $rptType unless $seen{$rptType}++;
Don't you think this would be faster than the grep, besides the fact that (I think) a grep for $rptTyp being 'a' would match a stored $rptType of 'XaX'.

I know! The OP had that code and maybe it's exactly what the OP intended, but it "smells fishy" ;-)

$\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print

Replies are listed 'Best First'.
Re^3: Pls help optomize - ksh version 60% faster!
by davidrw (Prior) on Sep 29, 2005 at 01:29 UTC
    Yes, you're right -- the hashing would be more efficient, though @rptType is used later in the code, so need to keep %seen in addition, or the later use might be able to be keys %seen instead of @rptType (unless order matters) .. or could just always push onto @rptType and throw out dups later (see tihs idiom, but destroys order)

    As for matching with /$rptType/, y, that seems suspicious .. i too now suspect that it should be eq instead, but can't say for sure..

    also, looking at this again, the first of my two lines is unnecessary -- it seemed at first that the author wanted a double push onto @rptType, but that's not the case.. I've ammended my post above..

    anyways, ++ and thanks for double-checking my post!!