in reply to WARNING t0mas wrote BAD CODE
in thread Odd file rename
The test-machine was a dual boot P233MHz/256RAM. The Program directory is on a FAT32 partition.use Benchmark; use File::Find; my $dirSep = $^O eq "MSWin32" ? "\\" : "/"; my $fileCounter=0; $t0 = new Benchmark; &test1('Program'); $t1 = new Benchmark; print $fileCounter . "\n"; $fileCounter=0; $t2 = new Benchmark; &test2('Program'); $t3 = new Benchmark; print $fileCounter . "\n"; print "test1: ",timestr(timediff($t1, $t0)),"\n"; print "test2: ",timestr(timediff($t3, $t2)),"\n"; sub test1 { my $Dir = shift; opendir(DIR, $Dir) || die "Can't opendir $Dir: $!"; my @Files = grep { /\.txt$/ && -f "$Dir$dirSep$_" } readdir( +DIR); rewinddir(DIR); my @Dirs = grep { /^[^.].*/ && -d "$Dir$dirSep$_" && ! -l "$ +Dir$dirSep$_"} readdir(DIR); closedir DIR; foreach (@Files) { $fileCounter+=1; } foreach $SubDir (@Dirs) { &test1(join($dirSep,$Dir,$SubDir)) +; } }; sub test2 { my ($Dir) = shift; find(\&found, $Dir); } sub found { -f && /\.txt$/ && ($fileCounter+=1); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Reinventing wheels based on bad benchmarks
by runrig (Abbot) on Jan 09, 2003 at 21:50 UTC | |
by t0mas (Priest) on Jan 10, 2003 at 08:23 UTC | |
by Aristotle (Chancellor) on Jan 11, 2003 at 18:11 UTC | |
by runrig (Abbot) on Jan 10, 2003 at 18:16 UTC |