#!/usr/bin/perl -w
use warnings;
use Benchmark;
my $current_time = time();
my $filename = "test.txt";
sub file_open {
open (FILE, "$filename");
close FILE;
}
sub stat_change {
utime($current_time, (stat($filename))[9], $filename);
}
timethese(3000000, {'openfile' => file_open(), 'changestat' => stat_change()});
####
[11:08:40 jhorner@gateway scripts]$ ./20000619-1.pl
Benchmark: timing 3000000 iterations of changestat, openfile...
changestat: 0 wallclock secs ( 0.40 usr + 0.00 sys = 0.40 CPU) @ 7500000.00/s (n=3000000)
(warning: too few iterations for a reliable count)
openfile: 0 wallclock secs (-0.33 usr + 0.00 sys = -0.33 CPU) @ -9090909.09/s (n=3000000)
(warning: too few iterations for a reliable count)
####
#!/usr/bin/perl -w
use warnings;
use Benchmark;
my $current_time = time();
my $filename = "test.txt";
sub file_open {
open (FILE, "$filename");
close FILE;
my $i;
$i++;
}
sub stat_change {
utime($current_time, (stat($filename))[9], $filename);
my $i;
$i++;
}
timethese(3000000, {'openfile' => file_open(), 'changestat' => stat_change()});
####
[11:10:32 jhorner@gateway scripts]$ ./20000619-1.pl
Benchmark: timing 3000000 iterations of changestat, openfile...
changestat: 1 wallclock secs ( 0.88 usr + 0.00 sys = 0.88 CPU) @ 3409090.91/s (n=3000000)
openfile: 2 wallclock secs ( 0.91 usr + 0.00 sys = 0.91 CPU) @ 3296703.30/s (n=3000000)