Skip to content

Instantly share code, notes, and snippets.

@stash
Created July 16, 2010 23:16
Show Gist options
  • Save stash/479046 to your computer and use it in GitHub Desktop.
Save stash/479046 to your computer and use it in GitHub Desktop.
Demonstration of perl array memory usage
#!/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