>>At 1:02 PM -0500 03/06/96, Hal Wine wrote: >>>This means you should either: >>>a) do a chdir() to the supplied directory, then always do an opendir() >>>on the current directory (':' for Mac, '.' for unix/dos). Or, >>>b) always prepend the directory to the filename returned by readdir(). >>> >>>My hunch is (a) runs faster on the Mac (due to internals of the Mac >>>file system), and no slower on other file systems. >> >>No, according to Matthias, a) shouldn't run faster. He said MacPerl fully >>expands relative pathnames to absolute pathnames before doing anything with >>them. and on June 4: >Well, I hate to disagree with Matthias, but (a) DOES run faster, and >works correctly, while (b) has bugs. (See attached script) Here's the >timing for 10,000 stats of a directory where the path string is 223 >characters, and 7 levels deep (excluding volume name): > Perl 5.0.7r1m: > 194 seconds for full path stat > 120 seconds for relative stat > MacPerl 4.1.8: > 200 seconds for full path stat > 126 seconds for relative stat > >So, we see that using a full path is about 60% slower than relative >directories. I agree with Hal. I have attached two little scripts which can be used for timing. <Speed 2> takes between 58% and 62% of the time taken by <Speed 1> Alan ============================================================================= #!perl #Speed 1 $begin = times; open (OUT, ">List 1"); $start = (shift @ARGV); lstat($start); print OUT "$start:\n"; &DoIt($start); sub DoIt { local($it) = @_; local(@files); if (-d _) { opendir(DIR, $it); @files = readdir(DIR); closedir(DIR); foreach ( @files ) { lstat("$it:$_"); unless (-d _) { "$it:$_" =~ /$start:(.*)/; $str = $1; print OUT ("$str\n"); next; } &DoIt("$it:$_"); } } } $finish = times; print OUT "\n",'Time taken = ',$finish - $begin,"\n"; ============================================================================= #!perl #Speed 2 $begin = times; open (OUT, ">FolderList 2"); (shift @ARGV) =~ /(.*):(.*)/; $a = $1; $b = $2; print OUT "$a:$b\n\n"; chdir("$a:$b"); lstat(":"); &dodir; sub dodir { local ($dir) = @_; local @files; local $item; if (-d _) { opendir(DIR, ":"); @files = readdir(DIR); close(DIR); unless (@files) {print OUT "$dir - empty folder\n"} foreach $item (@files) { lstat($item); $name = "$dir:$item"; unless (-d _) {print OUT "$name\n";next;} chdir($item); &dodir($name); chdir('::'); } } } $finish = times; print OUT "\n",'Time taken = ',$finish - $begin,"\n";