in reply to •Re: Why does File::Find chdir?
in thread Why does File::Find chdir?
You lost me there, when might it be less efficient to "specify a multiple step path" ?
I don't really use File::Find much, so I super searched for some example code to try benchmarking, and from what i can tell, all other factors being equal/irrelevant, no_chdir seems to be faster.
Here's an example from one of your snippets...
#!/usr/local/bin/perl use Benchmark qw(cmpthese); use File::Find; my %results; my $wanted = sub { if (-l) { # it's a symlink my ($dev, $ino) = lstat _; # reuse info from -l push @{$results{"$dev $ino"}}, $File::Find::name; if (-e) { # that points somewhere else my ($dev, $ino) = stat _; # reuse info from -e push @{$results{"$dev $ino"}}, "symlink:$File::Find::name"; } } else { my ($dev, $ino) = stat; push @{$results{"$dev $ino"}}, $File::Find::name; } }; my @dirs = qw(/bin /usr/bin /usr/sbin); # change this to "/" to do the cmpthese(1000, { chdir => sub { %results=(); find { wanted=>$wanted }, @dirs; }, no_chdir => sub { %results=(); find { wanted=>$wanted, no_chdir=>1}, @dirs; } }); __END__ laptop:~> monk.pl Benchmark: timing 1000 iterations of chdir, no_chdir... chdir: 79 wallclock secs (61.68 usr 13.90 sys + 1.23 cusr 1.03 +csys = 77.84 CPU) @ 13.23/s (n=1000) no_chdir: 82 wallclock secs (61.94 usr 17.99 sys + 1.07 cusr 1.09 +csys = 82.09 CPU) @ 12.51/s (n=1000) Rate no_chdir chdir no_chdir 12.5/s -- -5% chdir 13.2/s 6% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re^3: Why does File::Find chdir?
by merlyn (Sage) on Jul 13, 2004 at 14:25 UTC | |
by hossman (Prior) on Jul 14, 2004 at 06:06 UTC |