Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Building a small perl

by Animator (Hermit)
on Mar 20, 2009 at 17:55 UTC ( [id://752125]=note: print w/replies, xml ) Need Help??


in reply to Building a small perl

First: how much memory does the program use when you just run a syntax check? Or when add a exit; as the very first line of the script? (well the second after a sleep)

Is it the compiled program that is using the memory or is it the code that is being executed at runtime that is using a lot of memory?

What you should be doing (IMHO) is figure out what is using the memory.

One approach could be to add a system("ps -uh $$"); after every line.

IMHO you will not get a serious memory reduction by recompiling perl and setting/unsetting some options. The only way to reduce the memory is to look at the code of the application.

One example to show what I mean:

perl -wle 'system("ps uch $$");@x=1..1_000_000;print "Elements in \@x: + " . @x;; system("ps uch $$");' xxx 2395 0.0 1.0 46488 44384 pts/0 R+ 18:46 0:00 perl Elements in @x: 1000000 xxx 2395 0.0 1.5 66104 64012 pts/0 R+ 18:46 0:00 perl
vs
perl -wle 'system("ps uch $$");push @x, $i while ($i++ < 1_000_000);pr +int "Elements in \@x: " . @x;; system("ps uch $$");' xxx 2365 0.0 0.0 3152 1248 pts/0 R+ 18:45 0:00 perl Elements in @x: 1000000 xxx 2365 20.0 0.5 22992 21056 pts/0 R+ 18:45 0:00 perl

The array contains exactly the same information. The first program uses 64MB of memory and the second 22MB of memory. The first one uses more memory, the second one uses more CPU.

Same example but with a syntax check:

perl -wlce 'system("ps uch $$");@x=1..1_000_000;print "Elements in \@x +: " . @x;; system("ps uch $$");CHECK { system("ps uch $$"); }' xxx 2554 0.0 1.0 46488 44404 pts/0 R+ 18:50 0:00 perl -e syntax OK
vs
perl -wlce 'system("ps uch $$");push @x, $i while ($i++ < 1_000_000);p +rint "Elements in \@x: " . @x;; system("ps uch $$");CHECK { system("p +s uch $$") }' xxx 2521 0.0 0.0 3152 1260 pts/0 R+ 18:49 0:00 perl -e syntax OK

What this shows is that in the first program 45MB of memory is already being used before the code is being executed. That memory will only be free'ed/reused when perl stops.

update: To provider an anwsers on your question about: 'oplines - make perl runtime 8% faster and smaller' that messages is theoretical and you such read it as such. It certainly will not make the runtime of each and every application 8% faster and smaller. It all depends on where the memory is being used.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-20 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found