#!/usr/bin/perl # # the system call to cat is easy, but is it expensive? # use Benchmark qw( cmpthese timethese); use warnings; use strict; my $basefilename='MB_of_zeros.dat'; my $filename; sub cat_file { my @file_contents = `cat $filename`; } sub open_file { open (FILE_CONTENTS, $filename); my @file_contents = ; } foreach my $size (qw(1 10 100)) { $filename = $size . $basefilename; print "Reading $filename\n"; cmpthese (-30, { # number indicates seconds to run the test for (-5 is 5seconds) or total test runs to do (if number +) 'Cat File' => sub { cat_file() }, 'Open_File' => sub { open_file() }, }); }