Created
July 16, 2010 23:16
-
-
Save stash/479046 to your computer and use it in GitHub Desktop.
Demonstration of perl array memory usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
use Devel::Size qw/size total_size/; | |
use constant N => 1_000_000; | |
fillerup: { | |
my $x = [2 .. N]; | |
print size($x) . " " . total_size($x) . "\n"; | |
} | |
slide_along: { | |
my $x = [1]; | |
for (2 .. N) { | |
push @$x, $_; | |
shift @$x; | |
} | |
print size($x) . " " . total_size($x) . "\n"; | |
} | |
start_empty: { | |
my $x = []; | |
for (2 .. N) { | |
push @$x, $_; | |
shift @$x; | |
} | |
print size($x) . " " . total_size($x) . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment