Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

"benchmarking" memory usage

by salva (Canon)
on May 30, 2005 at 19:48 UTC ( [id://461853]=perlquestion: print w/replies, xml ) Need Help??

salva has asked for the wisdom of the Perl Monks concerning the following question:

I would like to do something like that:
use Memchmark qw(cmpthese); my @data = 1..$ARGV[0]; cmpthese(-1, { foo => sub { my @out = foo(@data) }, bar => sub { my @out = bar(@data) } });
but unfortunately, Memchmark doesn't exist yet... so my question is: how can memory usage be measured?

BTW, I don't need accurate numbers, an error around 25% could be admissible. I don't need it to be portable either, it should just work on Linux.

update: I have just uploaded Memchmark to CPAN.

Replies are listed 'Best First'.
Re: "benchmarking" memory usage
by Zaxo (Archbishop) on May 30, 2005 at 19:54 UTC

    Build a perl with DEBUGGING defined. That will allow you to use the -Dm run option, which tracks all memory allocations. See perlrun.

    After Compline,
    Zaxo

Re: "benchmarking" memory usage
by dug (Chaplain) on May 30, 2005 at 19:56 UTC
Re: "benchmarking" memory usage
by mda2 (Hermit) on May 30, 2005 at 20:18 UTC
    Recently I identified one memory leak on my webservice daemon (pure perl), and find resources to do it...
    Check modules Find::Globals, Devel::Size. These modules work on solaris box, but on linux other modules area available with some libraries dependencies (Devel::Leak, Devel::LeakTrace), but I don't used it.

    My compare with Devel::FindGlobals are text based:

    use Devel::FindGlobals; open(D, "> $0." . time() ); print D "Globals: ", print_globals_sizes(), "\n"; close(D); __END__ Globals: Name of SCALAR variable Size Total Size ================================================================= $AutoLoader::AUTOLOAD 48 48 $AutoLoader::VERSION 29 29 $Benchmark::VERSION 20 20 $Benchmark::cache 16 16 ... cut ... $Carp::Verbose 16 16 $Class::ReturnValue::() 28 28 $Class::ReturnValue::VERSION 29 29 $Click21::Dist::VERSION 20 20 $Click21::Dominio 16 1625 $Click21::Dominio::VERSION 20 20 ... cut ...
    After make two logs on pré-defined points, make a diff to identify size changes. .............

    --
    Marco Antonio
    Rio-PM

Re: "benchmarking" memory usage
by mirod (Canon) on May 30, 2005 at 21:09 UTC

    AFAIK Perl does not give back memory to the OS. So on Linux, if you put your code to benchmark in 2 different scripts, for each of them, just before exiting, you can get the memory used by your code in /proc/$$/status.

      This came up recently, but depending on the OS and your malloc(3) implementation you may see your perl process size shrink when free(3) gets called or you might not. Might be interesting to see a table of $^O / $Config{usemymalloc} / "will my process shrink?" across some different combinations.

      --
      We're looking for people in ATL

Re: "benchmarking" memory usage
by bofh_of_oz (Hermit) on May 30, 2005 at 20:22 UTC
    UPDATE: removed my post as irrelevant to the original question...

    --------------------------------
    An idea is not responsible for the people who believe in it...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://461853]
Approved by dug
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-19 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found