开发者

How do I interpret benchmark times as reported by Perl's Benchmark module?

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 t开发者_开发技巧imestr($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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜