#!/usr/local/bin/perl # # command line arg negative: build test dirs that deep # command line arg positive: test that many iterations use Benchmark qw(cmpthese); use File::Find; sub build { # build up our testing directory recursively my ($dir, $depth) = @_; chdir $dir; if (0 < --$depth) { mkdir 'a'; build('a', $depth); } `touch aa`; foreach (0..1) { `touch $_`; } foreach (5..6) { if (1 < rand 2) { `ln -s aa $_`; } if (1 < rand 2) { `ln aa $_$_`; } } chdir '..'; } 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 $arg = shift || 2; if (0 > $arg) { build('.', -$arg); } else { my %results; cmpthese($arg, { chdir => sub { %results=(); find { wanted=>$wanted }, '.'; }, no_chdir => sub { %results=(); find { wanted=>$wanted, no_chdir=>1}, '.'; } }); } __END__