On Sun, Jan 25, 2009 at 12:54:48AM EST, Paul Jarc wrote: > Chris Jones <cjns1...@gmail.com> wrote:
> > I would imagine the linux implementation of the sleep() function > > does not result in anything besides some system call or other? > > Right. But any time you're worried about performance (or more > generally, any sort of resource overuse), keep in mind these two > cardinal rules: > - The best opportunity for improvement is the part of the program that > consumes the most time/memory/etc. > - Finding the most expensive part of the program cannot be done > reliably by reading/thinking about the program, even for very > experienced programmers. Measurement is the only reliable way. > Attempts to improve a program's resource usage often make the program > harder to understand and maintain, so it's good to first make sure > that the change you're making will have a significant impact on the > overall system. That's another story, but I find the formulation of rule #2 above, misleading: reading, thinking, and yes, speculating, come first and measuring is how you prove or disprove your theories. More to the point, I am not attempting to optimize existing programs but rather rethinking the design of tools that started their life as little bash/awk one-liners about a year ago. They served their purpose, but only a week after I wrote them, I would not go near them, because trivial as they were, they were fine examples of "unmaintainable". I recently rewrote the one-liners as regular scripts, adding comments, changing the one-letter variables to something meaningful, adding code to handle error conditions, trying to adhere to coding standards.. etc. I can't say I had looked at it this way, but in a sense, what I had been doing all along amounted to prototyping the application. Since I am now rethinking the design with the end result likely to be radically different from the current implementation, I do not see much point in profiling the prototype.. work with known material and focus on learning the profiling tools, maybe.. that's about it. What prompted my original post was not a "replacing these sleep commands could be a major source of optimization for my scripts" but rather "hang on.. all these sleeping processes.. there's something wrong with this picture". Thank you for reformulating it earlier as "some scripting languages have a sleep builtin, others don't". CJ