Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: How can I optimize my script?

by kennethk (Abbot)
on May 04, 2017 at 00:03 UTC ( #1189466=note: print w/replies, xml ) Need Help??

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.
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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2021-10-19 21:22 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (77 votes). Check out past polls.