in reply to Re^2: sorting two arrays together
in thread sorting two arrays together
I always thought so, too. Interestingly, according to Devel::Size, the memory usage isn't all that different:
use Devel::Size qw(total_size); my @a; push @a, [$_,$_] for 1..2**16; print total_size(\@a); # one array of pairs my @b; push @b, $_ for 1..2**16; print total_size(\@b) * 2; # two arrays __END__ 4964080 4740496
(tested with perl, v5.10.1 (*) built for x86_64-linux-thread-multi, Devel::Size-0.72)
PS: although there is nothing random in the data, the sizes reported by Devel::Size vary by up to 15% from call to call (i.e. on some occasions the one array with pairs uses even less memory than two separate arrays). Why is that?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: sorting two arrays together
by JavaFan (Canon) on Dec 22, 2010 at 23:49 UTC | |
by Anonyrnous Monk (Hermit) on Dec 23, 2010 at 00:11 UTC | |
by BrowserUk (Patriarch) on Dec 23, 2010 at 01:19 UTC | |
by Anonyrnous Monk (Hermit) on Dec 23, 2010 at 01:27 UTC | |
by BrowserUk (Patriarch) on Dec 23, 2010 at 01:37 UTC | |
|