#!/usr/bin/perl use strict; use Benchmark; use File::Finder; use File::Find; my $Usage = "$0 some/path\n"; die $Usage unless @ARGV and -d $ARGV[0]; #chdir $ARGV[0] or die "can't chdir to $ARGV[0]"; # (no, don't chdir; just pass the target path to [Ff]ind... timethese( 50, { 'File::Finder module' => \&try_Finder, 'shell-find pipeline' => \&try_pipe, }); sub try_Finder { my $files = File::Finder->type('f'); find( $files->print, $ARGV[0] ); } sub try_pipe { open( FIND, "find $ARGV[0] -type f |" ); print while (); close FIND; } __END__ # Output: Benchmark: timing 50 iterations of File::Finder module, shell-find pipeline... File::Finder module: 9 wallclock secs ( 8.44 usr + 0.75 sys = 9.19 CPU) @ 5.44/s (n=50) shell-find pipeline: 2 wallclock secs ( 0.47 usr 0.06 sys + 0.38 cusr 0.50 csys = 1.41 CPU) @ 94.34/s (n=50) #### perl test-find.pl some_path | grep -v some_path