#!/usr/bin/perl use warnings; use strict; use Benchmark; sub with_chdir { my $d = shift; my $filecount = 0; chdir($d) or die "chdir: $!\n"; opendir(DIR,"."); while(my $f = readdir(DIR)) { ( -f $f) and $filecount++; } } sub without_chdir { my $d = shift; my $filecount = 0; opendir(DIR,$d); while(my $f = readdir(DIR)) { ( -f "$d/$f") and $filecount++; } } use constant TESTDIR => "/var/mail"; timethese(100, { with_chdir => sub { with_chdir(TESTDIR); }, without_chdir => sub { without_chdir(TESTDIR); }, });