in reply to Re^4: matching values in arrays
in thread matching values in arrays

I only suggested an other approach... in case the person doesn't have much memory but has enough time to run it...

The orignal arrays (accoring to Devel::Size::total_size) uses 152 bytes, the @which-array (posted by ysth), uses 629 bytes. Your hash of array references uses 2200 bytes.

Using the same code but whit your example arrays: 2_000_072 bytes (for the first two and 2_000_052 for the last one), @which-array: 11_397_188, hash of array references: 44_886_169 bytes, which is 3,9 times more then the array. And that is in my opinion a lot more.

Used code:

#!/usr/bin/perl -l use strict; use warnings; use Devel::Size qw/total_size/; #my @array1 = (1,2,3,4,5); #my @array2 = (6,7,8,9,10); #my @array3 = (11,12,13,14,15); my @array1 = (1 .. 100001); my @array2 = (100001 .. 200001); my @array3 = (200001 .. 300000); print total_size(\@array1); print total_size(\@array2); print total_size(\@array3); print "-" x 10; my @which; $which[$_] = "array1" for @array1; $which[$_] = "array2" for @array2; $which[$_] = "array3" for @array3; print total_size(\@which); print "-" x 10; my %which; do { push @{ $which{$_} } => "array1" } for @array1; do { push @{ $which{$_} } => "array2" } for @array2; do { push @{ $which{$_} } => "array3" } for @array3; print total_size(\%which);