The difference between the duration reported there and the duration of your current app is the upper bound on how much better you might be able to do.sub checkReadTime # call this with just your list of files { my $linecount = 0; my $starttime = time; for my $file ( @_ ) { my $fh = &openLogFile($file) or next; while ( <$fh> ) { $linecount++; } close $fh; } my $endtime = time; warn sprintf( "read %d lines from %d files in %d sec\n", $linecount, scalar @_, $endtime - $starttime ); }
Apart from that, if you have a serious problem with how long it's taking, maybe you should be doing more with the standard compiled unix tools that do things like sorting. For instance, you could put your filtering step into a separate script, pipe its output to "sort", and pipe the output from sort into whatever script is doing the rest of the work on the sorted lines.
If your app isn't geared to a pipeline operation like this:
then just put the first part of that into an open statement inside your main app:filterLogFiles file.list | sort | your_main_app
Of course, you can include option args for your filterLogFiles process so that it can skip the lines that you don't need depending on dates or whatever, and have it output the data in a form that will be easiest to sort (and easy for your main app to digest).open( my $logsort, "-|", "filterLogFiles @files | sort" ) or die $ +!; while ( <$logsort> ) { ... }
In reply to Re: How to improve speed of reading big files
by graff
in thread How to improve speed of reading big files
by korlaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |