Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Sometimes I want to know the amount of memory a Module takes.

package MemImpact; use vars qw($before $after $now); BEGIN { $before = `ps -o vsz= -p $$`; } $now = $before; printf "%-40s % 10d kB\n", "initial memory:" , $before; sub import { my $pack = shift; for (@_) { eval "use $_;"; die "Can't load $_:\n$@\n" if $@; $after = `ps -o vsz= -p $$`; printf "%-40s % 10d kB\n", "after loading $_:" , $after; printf "%-40s % 10d kB\n", "impact of $_:" , $after - $now; $now = $after; } } END { printf "%-40s % 10d kB\n", "total impact:" , $after - $before; } 1;

Usage example:

perl -MMemImpact=Moose,MooseX::AttributeHelpers -e 1

or

#!/usr/bin/perl use MemImpact qw(Moose); use MemImpact qw(MooseX::AttributeHelpers);
initial memory: 7576 kB after loading Moose: 13408 kB impact of Moose: 5832 kB after loading MooseX::AttributeHelpers: 14848 kB impact of MooseX::AttributeHelpers: 1440 kB total impact: 7272 kB

In reply to memory usage of modules by shmem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2023-12-09 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (38 votes). Check out past polls.

    Notices?