in reply to way to find module memory usage?

It won't give you the sizes directly, but the easiest way to convince yourself that your debug code is being exclused is to use B::Deparse, which for reasons I do not understand is invoked by adding -MO=Deparse to your command line.

This is what the output looks like when debug is enabled:

C:\test>type junk.pl #! perl -slw use strict; use constant DEBUG => 1; if( DEBUG ) { print "Debugging..."; } print "Not debugging..."; C:\test>junk.pl Debugging... Not debugging... C:\test>perl -MO=Deparse junk.pl BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use constant ('DEBUG', 1); use strict 'refs'; do { print 'Debugging...' }; print 'Not debugging...'; junk.pl syntax OK

Note how the conditional block has been replaced by a do block.

And this is what it looks like when debug is disabled:

C:\test>type junk.pl #! perl -slw use strict; use constant DEBUG => 0; if( DEBUG ) { print "Debugging..."; } print "Not debugging..."; C:\test>junk.pl Not debugging... C:\test>perl -MO=Deparse junk.pl BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use constant ('DEBUG', 0); use strict 'refs'; '???'; print 'Not debugging...'; junk.pl syntax OK

Note that the entire conditional block has been replaced by '???'.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Replies are listed 'Best First'.
Re^2: way to find module memory usage?
by perl-diddler (Chaplain) on Jun 06, 2018 at 20:37 UTC
    That certainly helps, though I would still like to see numbers!

    Think if you did bench mark testing and the only result you got back was whether or not routine "A" was faster than routine "B".

    Certainly helpful, but you'd probably want to know numbers -- by how much...etc.

    Thanks!

      That certainly helps, though I would still like to see numbers!

      My guess as to why noone has written a module for that is that it is of no great concern.

      Example, I have a generated perl file that basically was created to optimise a very heavily nested set of loops (over 100), by unrolling those loops.

      It is just under 4MB in size:

      07/06/2018 01:44 3,959,242 gened.pl 1 File(s) 3,959,242 bytes

      And consists of just over 50kloc:

      C:\test>wc -l gened.pl 50405 gened.pl

      When run, it executes 2.3 million lines:

      C:\test>perl -d:Trace gened.pl >log 2>&1 C:\test>dir log 07/06/2018 01:49 2,334,425 log 1 File(s) 2,334,425 bytes

      I just tacked these two line to the bottom of the file:

      sub mem2{ `tasklist /nh /fi "PID eq $$"` =~ m[(\S+ K)$]; } print mem2;

      And when run, it produces:

      [ 1:52:14.81] C:\test>tail gened.pl X4: L4( $s, $e, $p ); X3: L3( $s, $e, $p ); X2: L2( $s, $e, $p ); X1: L1( $s, $e, $p ); } Xsub( 99, 88, 77 ); sub mem2{ `tasklist /nh /fi "PID eq $$"` =~ m[(\S+ K)$]; } print mem2; [ 1:53:47.89] C:\test>gened 187,124 K

      So 50kloc of code compiles to <200MB of memory.

      Unless you're using Moose, the size of the code usually pales in significance with respect to the data. And the great benefit of properly optimised debug blocks is the removal of the condition test within inner loops and the runtime it saves.

      Not what you want to hear, but it might set your mind at rest about a few lines of debug.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit