Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Pls help optomize - ksh version 60% faster!

by Skeeve (Parson)
on Sep 28, 2005 at 22:48 UTC ( [id://495933]=note: print w/replies, xml ) Need Help??


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!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://495933]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-03-28 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found