f77coder has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I have two snippets of code which get the intersection of two hash arrays and am wondering about performance on large scale data.
In a nutshell, what kind of performance is to be expected using grep vs looping through hashes? looking at the grep source code, it has a lot of buffering, I've tried to find some details on internals of memory allocation of hashes but ???
I read this "This does mean that hashes eat up a I<lot> of memory, both in memory Devel::Size can track (the memory actually in the structures and strings) and that it can't (the malloc alignment and length overhead)." from here http://cpansearch.perl.org/src/TELS/Devel-Size-0.71/lib/Devel/Size.pm
or perhaps is it possible to unroll the loop and thread it?
my %inter; for (keys %hist1) { if (exists $hist2{$_}) { my $val1 = $hist1{$_}; my $val2 = $hist2{$_}; $inter{$_} = ($val1 <= $val2) ? $val1 : $val2; } }
my @common = grep exists $hist1{$_}, sort keys %hist2;
Thanks for any insight.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: memory:: grep vs looping through hash
by thomas895 (Deacon) on Aug 18, 2014 at 06:39 UTC | |
by f77coder (Beadle) on Aug 18, 2014 at 07:21 UTC | |
by thomas895 (Deacon) on Aug 19, 2014 at 01:09 UTC | |
|
Re: memory:: grep vs looping through hash
by Anonymous Monk on Aug 18, 2014 at 12:54 UTC | |
by f77coder (Beadle) on Aug 18, 2014 at 16:47 UTC | |
|
Re: memory:: grep vs looping through hash
by locked_user sundialsvc4 (Abbot) on Aug 18, 2014 at 12:54 UTC |