views:

55

answers:

1

Summary

When I execute a very simple program using Perl's Benchmark utility. I get values that are not (appearing as) milliseconds or nanoseconds. The benchmark data returned is not useful to me because I do not know how to interpret it.

Example:

use Benchmark;

my $start = Benchmark->new;
print "foo!";
my $end = Benchmark->new;

my $diff = timediff($end, $start);

print timestr($diff);

Returns: foo! 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)

What does the different fields mean: Wallclock seconds, Usr, Sys, CPU? Can they be extrapolated to get a millisecond value? Right now for my benchmarking, all I need is a real-world time for a single execution, without needing to account for some of the more esoteric aspects of benchmarks.

+3  A: 

Wallclock seconds is the actual elapsed time, as if you looked at your watch to time it.

The usr seconds in the time actually spent on the CPU, in user space.

The sys seconds is the time actually spent on the CPU, in kernel space.

The CPU time is the total time spent on the CPU.

However, once you have all of that, you have to figure out what you are actually trying to measure. The Benchmark module only times what you do on the local machine. If you have to fire off processes on a remote machine (e.g. a database server or web server), the CPU times of those machines aren't part of the result. However, the time you spend waiting for their responses are part of the wallclock time.

Your results show that everything happened almost instantaneously. You need something more meaty in there so it takes up some time. If you just need the wallclock time for a single run, you don't need to use Perl at all. Use the times utility from the command line.

I get into this fairly extensively in Mastering Perl and some of my benchmarking talks. However, just this week I think the Benchmark module became obsolete. Steffen Müller's Dumbbench does a much better job. See his dumbbench blog entries at blogs.perl.org.

brian d foy
I'd be careful about saying Benchmark.pm is obsolete. It does what it advertises, even if the interface is... interesting. The very purpose of Dumbbench is to take some control from the user to reduce the probability of P of misunderstanding statistics EBKAC. This leads to having to run more iterations of long-running commands than otherwise necessary if you just care about the expectation value.
tsee
I've never really liked Benchmark. I'm looking forward to the day when it is not the tool we use. :)
brian d foy