http://qs321.pair.com?node_id=1189466


in reply to How can I optimize my script?

Others have suggested going parallel. I'll address the actual question of optimization.

You are running into the classic challenges of taking advantage of a library. If I run the code

time perl -E'say "This is my $_ test message!" for 1 .. 1000000' > jun +k.txt
on my command line, it takes time about half a second. Why does it take orders of magnitude more time for your subroutine call to syslog than just a simple disk print? If we review the module source code (here), you can see all sorts of computation that is replicated unnecessarily a million times. I'd highly recommend you use a profiler (I use Devel::NYTProf) to see where time is actually being spent. I would expect that if you copied the syslog subroutine out of the module, it would run just fine with a small amount of rehab, such as changing
local $facility = $facility; # may need to change temporarily.
to
local $facility = $Sys::Syslog::facility; # may need to change temp +orarily.
Once it's running, then you'll have the capability to pull as much out of that big loop as possible, guided by the profiler. What you get with a library is ease of use, but you get limited because libraries are written for the general case. And that's why open source is great.

Alternatively, you can decide your time is more valuable than the computer's, and just leave it running overnight/all week/until the heat death of the universe.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.