Finite memory

acme on 2009-01-22T16:50:24

Computer memory is sadly still finite. Sometimes it's interesting to know how much memory a Perl script might be taking at a particular time. If you install the GTop development headers and library you can use:

#!perl
use strict;
use warnings;
use GTop ();
use Number::Bytes::Human qw(format_bytes);

my $gtop     = GTop->new;
my $proc_mem = $gtop->proc_mem($$);
my $size     = $proc_mem->size;
print format_bytes($size) . "\n";

Which produces something like:

6.2M

So you can find out that the module you were criticising isn't bloated code after all...


improved version

daxim on 2009-01-22T18:31:58

To calculate the actual overhead you should substract what Perl needs for itself. See "perlbloat.pl" in the mod_perl manual.

That program has a small bug, if one wants to load a naked Foo.pm file, it gives Warning: Use of "require" without parentheses is ambiguous at (eval 4) line 1. To make it work correctly:

-      if (eval "require $_") {
+      if (eval "require q($_)") {