OxPM: Re: Benchmarking modules?

Dave Page grimoire at sparky.ox.compsoc.net
Tue Feb 17 12:04:01 CST 2004


On Tue, Feb 17, 2004 at 05:35:06PM -0000, Jon Rees wrote:
> http://search.cpan.org/~nwclark/perl-5.8.3/lib/Benchmark.pm

>     use Benchmark;
>     $t0 = new Benchmark;
>     # ... your code here ...
>     $t1 = new Benchmark;
>     $td = timediff($t1, $t0);
>     print "the code took:",timestr($td),"\n";

> There is a 'fine' timing variant available....

Benchmark::Timer is even easier:

	use Benchmark::Timer
	my $timer = Benchmark::Timer->new();

	$timer->start('Executing function foo()');
	foo();
	$timer->stop;

	$timer->start('Executing function bar()');
	bar();
	$timer->stop;

	$timer->report;

This will dump details of each task and how long it took to STDERR; if
you specify a tag more than once, it will give you averages etc. as
well.

Dave
-- 
"Sir, you have just redefined fucked-up." - Art, #keble, 12/05/2003
IM: grimoire at jabber.earth.li | http://sparky.ox.compsoc.net/~grimoire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/archives/oxford-pm/attachments/20040217/f94cfe85/attachment.bin


More information about the Oxford-pm mailing list