Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Benchmarking Your Code

by turnstep (Parson)
on Apr 24, 2000 at 22:05 UTC ( #8745=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use Benchmark;
    
  2. or download this
    $x = timeit($count, 'CODE');
    ## CODE is run $count times
    ## $x becomes a Benchmark object which contains the result
    print "Result from $count loops: ";
    print timestr($x), "\n";
    
  3. or download this
    $x = timethis($count, 'CODE');
    
    ## or even just:
    
    timethis($count, 'CODE');
    
  4. or download this
    @x = timethese($count, { 'one','CODE1', 'two','CODE2' });
    
  5. or download this
    timethese($count, {
      'one'   => 'CODE1',
      'two'   => 'CODE2',
      'pizza' => 'CODE_X', ## etc....
    });
    
  6. or download this
    $x = timeit($count, 'CODE1');
    $y = timeit($count, 'CODE2');
    $mydiff = timediff($x, $y);
    
  7. or download this
    #!/usr/bin/perl
    use Benchmark;
    ...
    
    exit;
    
  8. or download this
    Benchmark: timing 10 iterations of Sort One, Sort Two...
      Sort One:  0 secs ( 0.33 usr  0.00 sys =  0.33 cpu)
                (warning: too few iterations for a reliable count)
      Sort Two:  1 secs ( 0.48 usr  0.01 sys =  0.49 cpu)
    
  9. or download this
    Benchmark: timing 150 iterations of Sort One, Sort Two...
      Sort One:  5 secs ( 4.89 usr  0.01 sys =  4.90 cpu)
      Sort Two:  8 secs ( 7.12 usr  0.01 sys =  7.13 cpu)
    
  10. or download this
    $count = shift || die "Need a count!\n";
         
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://8745]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (16)
As of 2014-12-19 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (91 votes), past polls