I didn't write to scripts below, but they are fun to play with.
Obviously some adjustment would be needed to compare across systems.
#################################################
#!/usr/bin/perl Benchmark_demo1
#Measure CPU usage of a some portion of a program
use Benchmark;
# generate list of all text files in /etc
@text_files = grep { -f and -T } glob('/etc/*');
timethis(100, 'sort_by_size(@text_files)');
# sort the files names according to file sizes
sub sort_by_size {
my @files = @_;
@files = sort { -s $a <=> -s $b } @files;
return @files;
}
#################################################
#####################################################
#!/usr/bin/perl Benchmark_demo2
#Can confirm that one technique is faster than another
use Benchmark;
# generate list of all text files in /etc
@text_files = grep { -f and -T } glob('/etc/*');
timethis(100, 'faster_sort_by_size(@text_files)');
# sort the files names according to file sizes,
# stat'ing each file just once
sub faster_sort_by_size {
my @files = @_;
@files = map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
map { [ -s $_, $_ ] } @files;
return @files;
}
#####################################################