You should probably test on a smaller data set then? Anyway, I'm getting different results, my original code being roughly 55% faster on my single user machine (as expected).
I added a native Perl implementation that walks the tree itself with no overhead and that gains you another significant speed boost.
D:\ENV>perl pm10.pl
Holli (New). Found: 1 ( D:\env\Videos/2012 )
Time: -19
Holli (original). Found: 1 ( d:\env/Videos/2012 )
Time: -32
ovedpo15. Found: 1 ( d:/env/Videos/2012 )
Time: -51
Using this code.
use File::Find;
use File::Spec::Functions;
use Cwd qw(abs_path);
sub holli2
{
my @found;
my $path = 'd:\env';
my $target = "2012.avi";
myfind( \@found, $path, $target );
print "Holli (New). Found: ", scalar @found, " ( @found )", "\n";
}
sub myfind
{
my ($found, $path, $target ) = @_;
if ( opendir( my $in, $path ) )
{
while ( my $dir = readdir($in) )
{
next
if $dir =~ /^\.\.?$/;
my $entry = "$path/$dir";
if ( -d $entry )
{
myfind( $found, $entry, $target )
}
else
{
push @$found, $path
if ($dir eq $target) && (!-e "$path/.ignore");
}
}
closedir($in);
}
else
{
print qq(Skipping "$path": $!\n);
return;
}
}
sub holli
{
my @found;
my $path = 'd:\env';
my $target = "2012.avi";
find ( sub {
# We're only interested in directories
return
unless -d $_;
# Bail if there is an .ignore in the current directory
return
if -e "$_/.ignore";
# Add to the results if the target is found here
push @found, $File::Find::name
if -e "$_/$target";
}, $path);
print "Holli (original). Found: ", scalar @found, " ( @found )", "
+\n";
}
sub ovedpo15
{
my @found;
find( sub { get_dirs( \@found, $_ ) }, 'd:\env');
print "ovedpo15. Found: ", scalar @found, " ( @found )", "\n";
}
sub get_dirs {
my ($dirs_aref, $current_path) = @_;
$triesOvedpo15++;
eval {
my $abs_path = abs_path($current_path);
my $file = $abs_path."/2012.avi";
my $ignore_file = $abs_path."/".".ignore";
push (@{$dirs_aref},$abs_path) if((-e $file) && !(-e $ignore_f
+ile));
};
}
my $t = time();
holli2();
print "Time: ", ($t - time), "\n";
$t = time();
holli();
print "Time: ", ($t - time), "\n";
$t = time();
ovedpo15();
print "Time: ", ($t - time), "\n";
holli
You can lead your users to water, but alas, you cannot drown them.