Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
No such thing as a small change

(crazyinsomniac) Re: Performance quandary

by crazyinsomniac (Prior)
on Feb 23, 2002 at 08:48 UTC ( #147054=note: print w/ replies, xml ) Need Help??

in reply to Performance quandary

I have at least 2 things to tell you about.
My comments start with ##

sub add_entry { $log->print("Entering add_entry.", 3); my ($md5, $method, $key, $exists, $children) = @_; my ($parent, $parentmd5, $parentchildren); unless ( $children ) { $children = ''; } ## useless use of join ## "$key $exists $children" better used here $urldb->db_put($md5, (join(' ', $key, $exists, $children))); # It's an old entry--it already has parents. Can leave. ## useless use of a regular expression ## if( index($children,':') != -1) { # better used here if ( $children =~ ':' ) { return; } $parent = find_parent($key); # No more parents, or can't parent ourselves... if ( $parent eq "http:/" or $parent eq $key ) { return; } $parentmd5 = uc(md5_hex($method, $parent)); if ( $urldb->db_get($parentmd5, $object)==0 ) { ## inefficient use of split here ## see perlfunc split for more details (try the 3 arg) ## split /PATTERN/,EXPR,LIMIT ## so ## $parentchildren = (split(' ',$object,3))[2]; $parentchildren = (split (' ', $object))[2]; } else { $parentchildren = ''; } unless ( $md5 ) { $md5 = ''; $log->print("What, I say, what?!", 3) +; } # Is this child already listed? ## style point, do you know what $foo =~ $bar is? ## are you going to remember? ## is $md5 a regex parrern? ## always be explicit (add //) ## useless use of a regex here as well ### unless(index($parentchildren,$md5) != -1) { # is better unless ( $parentchildren =~ $md5 ) { if ( $parentchildren ) { $log->print("Inserting parent: $parent with children: $par +entchildren:$md5", 3); add_entry($parentmd5, $method, $parent, 0, "$parentchildre +n:$md5"); } else { $log->print("Inserting parent: $parent with child: $md5", +3); add_entry($parentmd5, $method, $parent, 0, $md5); } } return; }
Now i've seen you test/manipulate $parentchildren a few times using m// or split ... you might think of turning $parentchildren into somekind of hash or something, cause memory is easier to spare than extra function calls, right? (i think so)


Comment on (crazyinsomniac) Re: Performance quandary
Download Code
Re: (crazyinsomniac) Re: Performance quandary
by SwellJoe (Scribe) on Feb 23, 2002 at 10:59 UTC
    Thanks crazyinsomniac,

    Your suggested changes made a measurable difference (5%+, I think). I'm making similar alterations to the rest of my routines now. Though their impact is much less than add_entry, it certainly won't hurt to drop out a few regexes and splits/joins.

    And I've learned a nifty new function, index(). I always knew there was a way to do that, I just never figured out what it was.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-03-17 16:29 GMT
Find Nodes?
    Voting Booth?

    Have you used a cryptocurrency?

    Results (355 votes), past polls