Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Pathological example

by sleepingsquirrel (Chaplain)
on Jul 29, 2004 at 17:54 UTC ( [id://378446]=note: print w/replies, xml ) Need Help??


in reply to code execution speed and variable name length

Read (and heed) what the others above said about premature optimization. But here's what I get for one pathalogical exaple using large hash keys.
greg@sparky:~/perl$ cat hashing_short #!/usr/bin/perl my $short="a"; my $long="This is a long hash key"x1000; my %h; $h{$short}++ for (1..1000000); greg@sparky:~/perl$ time hashing_short real 0m0.376s user 0m0.375s sys 0m0.001s greg@sparky:~/perl$ cat hashing_long #!/usr/bin/perl my $short="a"; my $long="This is a long hash key"x1000; my %h; $h{$long}++ for (1..1000000); greg@sparky:~/perl$ time hashing_long real 2m46.893s user 2m38.196s sys 0m0.278s


-- All code is 100% tested and functional unless otherwise noted.

Replies are listed 'Best First'.
Re: Pathological example
by hv (Prior) on Jul 30, 2004 at 12:33 UTC

    By my calculation, your benchmark shows that each additional character in the hash key is costing you about 6.8 nanoseconds per lookup. That's probably the figure to be concentrating on in deciding how relevant this is.

    Hugo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-28 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found