Perl Basics
Introduction to Perl
FAQ's
CGI
Regular Expressions

PC Overview
Cool Stuff
My Modules
Success Stories
Links
Perl in the News
Logos
Perl @ msn
Perl Chat

PC Internals
About
Contact
Guest Book
Handy Logos
What's new

Benchmark

The Benchmark module encapsulates a number of routines to help you figure out how long it takes to execute some code.
See also r1057
P-friendly

[ home ] - [ search ] - [ sitemap ]

timethis - run a chunk of code several times

timethese - run several chunks of code several times

cmpthese - print results of timethese as a comparison chart

timeit - run a chunk of code and see how long it goes

countit - see how many times a chunk of code runs in a given time

#!/usr/bin/perl -w

use strict;
use Benchmark;

my $count = 3;

my $t = timeit($count, \&mysub);

print "$count loops of code took:", timestr($t), "\n";

sub mysub () {
        my $j = 0;
        for (my $i = 0; $i < 1000000; $i++) {
                $j++;
        }
}

Output

...3 loops of code took: 2 wallclock secs ( 2.87 usr +  0.00 sys =  2.87 CPU) @  1.05/s (n=3)
home - feedback - search - web jobs
© 1998-2004 retoh :)