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

Re: Fast data structure..!!!

by samtregar (Abbot)
on Apr 15, 2008 at 16:34 UTC ( #680566=note: print w/ replies, xml ) Need Help??


in reply to Fast data structure..!!!

This is around 20% faster in my tests and should use less memory (I didn't check how much):

my %save; for(0 .. 2000000) { $save{$_,$_+1}=$_+2; }

The difference is that this version creates just one hash and fills it with data in compound keys (joined with $;, \034 by default). Your version created lots of sub-hashes, allocating memory for each one. Using an array is even faster though.

I once solved a problem like this by using XS to compile a shared object containing a packed C data structure with my data, along with accessor routines also written in C. Then at runtime the Perl code just loaded the shared-object to get access to the data. It was really, really fast but I doubt I'd do it again - Berkeley DB has pretty much solved this problem.

-sam


Comment on Re: Fast data structure..!!!
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2015-07-07 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls