Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: system "gzip $full_name" is taking more time

by bulk88 (Priest)
on Dec 08, 2013 at 04:11 UTC ( #1066182=note: print w/ replies, xml ) Need Help??


in reply to Re: system "gzip $full_name" is taking more time
in thread system "gzip $full_name" is taking more time

To continue on wazat's post, use substr and eq instead of regexs for such ridiculously simple patterns. It will be faster.

my $file_time = (stat($full_name))[9]; my $diff = $now - $file_time; $diff = $diff / 86400; my $read = localtime($file_time);
combine statements 1, 2, and 3. Something like
my $file_time; my $diff = ($now - ($file_time = (stat($full_name))[9])) / 86400; my $read = localtime($file_time);
less assignments/reads and less pp_nextstate ops.
$diff = $diff / 86400; my $read = localtime($file_time); if ( $diff > 93 ) { print FILE "$full_name : $diff : $read\n"; unlink "$full_name"; } elsif ( $diff > 3 ) { next if (/\.gz/);
Optimize out the division by multiplying 93 and 3 by 86400, and comparing to the larger numbers than doing the division. And substr/eq instead of the .gz regex.
unlink "$full_name";
That looks bizzare like someone who has never done Perl before, don't do that.
my $read = localtime($file_time);
Don't do that, don't print the converted time to console, just the unix time. If someone really wants read the log they can do the conversion themselves.

IDK if you can do it with stat() or not, but get the -f and -d and stat on $full_name into exactly ONE syscall, save results to lexicals, then process the results. Don't do redundant I/O calls.

I would guess if you used Nytprof (you should have used that BEFORE coming to perlmonks), your script is either I/O bound to disk/filing system or CPU bound in gzip compression algoritm.


Comment on Re^2: system "gzip $full_name" is taking more time
Select or Download Code
Re^3: system "gzip $full_name" is taking more time
by parv (Priest) on Dec 09, 2013 at 08:20 UTC

    Others may make arguments for benchmarks regarding various points above.

    ... don't print the converted time to console, just the unix time. If someone really wants read the log they can do the conversion themselves. -- bulk88

    Not converting the time would be good enough if there won't be further use of the log. Otherwise, that places a high cost on the person reading to do the time conversions to be able to find the relevant entries. And, have a damn functioning log.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-08-28 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls