#!/usr/bin/perl use strict; use Benchmark; $L::glob = "/usr/local/*/*"; @L::files = glob $L::glob; print "Testing with " . @L::files . " files\n"; my $transform = q|map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M ]|; my $sort = q|sort { -M $a <=> -M $b }|; my $code = { assign => q| my @r = @L::files |, 'glob' => q| my @files = glob $L::glob |, sort_names => q| sort { $a cmp $b } @L::files |, sort_names_assign => q| my @r = sort { $a cmp $b } @L::files |, sort_times_assign => q| my @r = $sort @L::files |, ordinary_orig => qq| my \@r = $sort glob \$L::glob |, ordinary_mod => qq| my \@r = $sort \@L::files |, schwartz_orig => qq| $transform, glob \$L::glob |, schwartz_orig_assign => qq| my \@r = $transform, glob \$L::glob |, schwartz_mod => qq| my \@r = $transform, \@L::files |, } ; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # print "Timing for 2 CPU seconds...\n"; timethese( -2, $code ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $iterations = 1_000; print "-" x 73, "\n"; print "Timing for $iterations iterations\n"; timethese( $iterations, $code );