Dear Esteemed Monks,
In an effort to squeeze the utmost speed out of a large-scale lexical processing program I'm working on, I encountered advice that subs are slow in Perl; I have two functions in my program: one that recursively traverses a directory structure finding files, and one that takes those files and processes them entry by entry. In an attempt for a speed-boost I'm trying to remove those subs and make them in-line loops. So, two questions:
Question 1: is it worth it?
in the end, my directory-search routine will be called over an upward bound of around 100,000 files in several directories. Each time, it will call the second routine (processing the individual files). Would the gains be likely to be worth making this a loop instead of a sub?
Question 2: how to rewrite File::Find recursive function calls?
The sub looks like this, with the recursive line being the 'find' line :
sub _process_files {
my $file = shift;
...
# .json file
if (-f $file and ($file =~ /\.json\Z/)) {
_process_json($file);
}
# Directory
elsif (-d $file) {
# for each file in directory, process
find ( { wanted => sub { \&_process_files($File::Find::name) if -f
+},
no_chdir => 1 }, "$file");
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.