|XP is just a number|
Re: How can I optimize my script?by kennethk (Abbot)
|on May 04, 2017 at 00:03 UTC||Need Help??|
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
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
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.