Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Pathological example

by sleepingsquirrel (Hermit)
on Jul 29, 2004 at 17:54 UTC ( #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 (Parson) 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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2022-12-01 17:57 GMT
Find Nodes?
    Voting Booth?