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.
In reply to memory:: grep vs looping through hash by f77coder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |