Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

why the perl complied code takes more memory?

by arunstunner (Initiate)
on Mar 02, 2013 at 05:08 UTC ( #1021384=perlquestion: print w/ replies, xml ) Need Help??
arunstunner has asked for the wisdom of the Perl Monks concerning the following question:

Following is a sample code file name is while.pl
#! /usr/bin/perl use strict ; use warnings ; my $i=0 ; while (1) { print "Testing $i\n" ; $i++ ; sleep(1); }
I have compiled this code by using
perlcc -o compiled while.pl

Then I executed the normal code "while.pl" and compiled code "compiled". I seen the memory and cpu usage using the ps command

ps axo %cpu,%mem,command | grep "while\|compiled" 0.0 0.0 /usr/bin/perl ./while.pl 0.0 0.1 ./compiled

why complied code taking more memory comparing with while.pl?

How to avoid the memory usage of the compiled perl code?

Comment on why the perl complied code takes more memory?
Select or Download Code
Re: why the perl complied code takes more memory? (perlcc)
by Anonymous Monk on Mar 02, 2013 at 06:11 UTC

    Its unknowable (unless you're a c-expert ), and there really isn't anything you can do about it

Re: why the perl complied code takes more memory?
by igelkott (Curate) on Mar 02, 2013 at 08:29 UTC

    There could differences in optimization but the main difference should be static vs dynamic linking. Besides making the executables larger, static linking sometimes uses more memory (bigger symbol tables?).

    I'm not an expert but that's what I remember from my C days. Any more detail would probably be a bit too OT anyway.

Re: why the perl complied code takes more memory?
by rjt (Deacon) on Mar 02, 2013 at 09:44 UTC

    Your program is much too trivial to draw any conclusions about compiled Perl memory usage, and it's only a single data point, at that. You also need to look deeper into the OS memory to see how much of that is shared, vss, rss, etc. (and come with an understanding of what that means).

    To more accurately test, you would need to have code that uses significant memory with each of the various (Perl) reference types, and independently test the effects of code size, module dependencies, XS/I::C code, and then you'd start to get an idea for your system.

    My suggestion would be to not worry about it too much and focus on writing elegant memory- and CPU-efficient code. Your gains will almost certainly be much greater on that front.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-12-17 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (40 votes), past polls