#!/usr/bin/perl -Tw use strict; use Benchmark; use File::Temp qw(tempdir tempfile); use IO::Dir (); use IO::File (); ### what directories to use for testing my @DIRS = qw( /tmp /mnt/club/s01/tmp /mnt/club/s03/tmp /mnt/club/s05/tmp /mnt/club/s06/tmp /mnt/club/s09/tmp /mnt/club/s10/tmp /mnt/club/gw/tmp ); ### how many temporary files should it be created? my $FILES = 2_000; ### what should be the size of each temporary file? my $FILESIZE = 10_240; ### what template should it use for file creation? (use at least 4 'X') my $TEMPLATE = 'nfs_test_XXXXXX'; ### should I delete temporary files at program end? my $CLEANUP = 1; $| = 1; { ### helper routines my ($t0, $t1); sub Tinit { print " @_: 000%"; $t0 = new Benchmark; } sub Tend { $t1 = new Benchmark; print $/, ' ', timestr(timediff($t1, $t0)) , $/; } sub Show { print "\b" x 4; printf "%03d%%", $_[0] * 100/$FILES; } sub dir_based_test { my ($tmpdir, $type, $title) = @_; Tinit($title); my $d = new IO::Dir $tmpdir or warn "Can't open directory $tmpdir: $!\n", return; my $idx = 0; (my $tmatch = $TEMPLATE) =~ s/X/./g; while (defined($_ = $d->read)) { next unless /$tmatch/o; if ($type eq 'read') { my $fh = IO::File->new("$tmpdir/$_") or warn "$!\n", next; while (<$fh>) {} $fh->close; } elsif ($type eq 'stat') { stat("$tmpdir/$_") or warn $!,$/, next; } Show(++$idx); } $d->close; Tend; } } { ### running tests for each directory print "Test starting with $FILES files, $FILESIZE bytes each\n"; foreach my $dir (@DIRS) { ### creating a temporary subdirectory in the test directory. my $tmpdir = tempdir( $TEMPLATE, DIR => $dir, CLEANUP => $CLEANUP); print "$tmpdir\n"; ### creating test files Tinit 'files writing'; foreach (1 .. $FILES) { my ($fh, $fname) = tempfile($TEMPLATE, DIR => $tmpdir, UNLINK => 0); print $fh 'A' x $FILESIZE; close $fh; Show($_); } Tend; dir_based_test($tmpdir, 'list', 'directory listing'); dir_based_test($tmpdir, 'stat', 'files status'); dir_based_test($tmpdir, 'read', 'files reading'); } }