Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Ref to hash entries are faster?

by Tanktalus (Canon)
on Nov 29, 2006 at 20:29 UTC ( [id://586817]=note: print w/replies, xml ) Need Help??


in reply to Ref to hash entries are faster?

Methinks you're overly worried about optimising things ;-) So much so that you're making small typos that will cause you no end of headache (well, it'll end if you're using strict... but still be headaches while you sort it out).

ELEMENT: foreach my $key (keys %Contracts) { $tot_count++; # hmmm... { # lock block lock @{$Contracts{$key}}; my $Cntrct_ref = $Contracts{$key}; # note: no backslash next ELEMENT if $Cntrct_ref->[STATE] eq $ST_VOID or $Cntrct_ref->[STATE] eq $ST_ +REPORTED; $elapsed_time = time() - $Cntrct_ref->[START]; ...
Note the arrows. Much like C/C++'s pointers. Now, as to speed - I think that your first example will outperform the second as long as accuracy is also important. ;-) And that brings me to my point: don't fret about minor details like this. It's much easier to make correct code fast than fast code correct. So, I'd say that you should just get it working, and, if it's not fast enough, profile it and then see where it can be sped up.

You're worried about hash-lookup times in a byte-code language. That just doesn't seem to be a productive use of worrying time to me ;-)

Replies are listed 'Best First'.
Re^2: Ref to hash entries are faster?
by shotgunefx (Parson) on Nov 29, 2006 at 20:36 UTC
    It's a tough one to let go. Before Perl, most of my coding was C and ASM in a day when 66mhz was cutting edge. The urge to overly optimize was great :(

    -Lee
    "To be civilized is to deny one's nature."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-19 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found