Skip to content

Instantly share code, notes, and snippets.

@perlancar
Created October 12, 2012 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlancar/3879084 to your computer and use it in GitHub Desktop.
Save perlancar/3879084 to your computer and use it in GitHub Desktop.
quickly get the size of perl data structures from the command line
#!/usr/bin/perl
use Devel::SizeMe qw(:all);
unless (@ARGV) {
print "Usage: $0 <data-def-in-perl> ...\n";
print "Example: $0 '[1,2,3]' '{foo=>1}'\n";
exit 1;
}
for (@ARGV) {
print "$_: ";
eval qq[print total_size($_), "\n"];
}
@perlancar
Copy link
Author

Sample output:

$ sizeme 1
1: 24
$ sizeme '"str"'
"str": 56
$ sizeme '[]'
[]: 64
$ sizeme '{}'
{}: 120
$ sizeme '{foo=>1}'
{foo=>1}: 205
$ sizeme '[1..100]' '{1..200}'
[1..100]: 3264
{1..200}: 9525
do { require DateTime; DateTime->now }: 24757
$ sizeme 'do { require DateTime; [map {DateTime->now} 1..10] }'
do { require DateTime; [map {DateTime->now} 1..10] }: 38677
$ sizeme 'do { require DateTime; [map {DateTime->now} 1..100] }'
do { require DateTime; [map {DateTime->now} 1..100] }: 176917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment