Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^3: grab oldest file

by Tanktalus (Canon)
on Jul 06, 2006 at 23:43 UTC ( #559692=note: print w/replies, xml ) Need Help??

in reply to Re^2: grab oldest file
in thread grab newest file

The first one. However, the reason for "a)" above was not about resources used, it's more about resources available. What is the responsiveness required by your code, and is it meeting that responsiveness requirement?

One thing about premature optimisation is that many programmers make the mistake of thinking that saving CPU time is important in and of itself. It isn't - if you don't use the CPU time, the CPU probably will sit idle instead. The delta cost in electricity probably isn't going to be noticed, and surely will be less than paying for your time or electricity in posting your question.

If, however, your script computer is going through this particular piece of code thousands of times per second, where the difference of this overhead is important, well, that becomes another matter. For example, in a heavily-used web server (where "heavily-used" is entirely dependant on the web server and the overall CPU intensity of the CGI code).

Mind you, if your question was "I'm trying to get this to work on a Windows box and I'm trying to avoid requiring everyone to install the GNU tools", then that would be a very good answer to my question "a" above. In that case, it would no longer work ;-)

As to why the first one uses less resources: the second one launches three processes, and sets up two pipes. The first one does everything in the current process. Even on unix/linux where fork overhead is relatively small, creating processes still is a fairly large overhead (e.g., doing lots of stuff to the process tables in the kernel, lots of memory management, etc.). The processes? Obviously, /bin/ls and /bin/tail (or wherever they are). But also /bin/sh. And perl creates a pipe from sh to itself, while sh creates a pipe from ls to tail. I'm not sure how much overhead there is in creating pipes - but it has to be more than not creating pipes ;-)

Replies are listed 'Best First'.
Re^4: grab oldest file
by hasimir44 (Sexton) on Jul 06, 2006 at 23:49 UTC
    That's exactly what I wanted to know. I realize that it doesn't matter at all in this example. However, I hope to someday create something where it will matter and now I at least have a better understanding. namaste

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2023-09-22 12:15 GMT
Find Nodes?
    Voting Booth?

    No recent polls found