NAME

Benchmark::OO - Simple interface to do benchmarking.

SYNOPSIS

use Benchmark::OO;

print "Benchmarking for loop runs 2000 times.\n";
#Sart benchmarking here
my $obj = Benchmark::OO->start();

for(my $i = 0; $i < 2000; $i++) {
}

#First pause
$obj->pause();

print "Benchmarking for loop runs 1000 times.\n";
#First resume
$obj->resume();

for(my $i = 0; $i < 1000; $i++) {
}

#Second pause
$obj->pause();

print "Benchmarking for loop runs 500 times.\n";
#Second resume
$obj->resume();

for(my $i = 0; $i < 1000; $i++) {
}

#Final stop of benchmarking
$obj->stop();

#Print total result in tabluar form
$obj->print_benchmark();

#Get benchmark result on return hash form
my $ret = $obj->get_benchmark();
require Data::Dumper;
print Data::Dumper::Dumper($ret);

DESCRIPTION

This is a simple benchmarking module, can be used to get the banchmark at any part of code or complete code.

There are four functions (start(it is also constructor), pause, resume, stop) in this module to perform benchmarking. It is recommended to use these functions in logical order. otherwise total benchmarking result will be having incorrect value.

There are two fundtions, (print_benchmark and get_benchmark) to get result of benchmark.

start

This function will start benchmarking.

pause

This function will pause benchmarking. Should be called after start or resume.

resume

This function will resume benchmarking, which was paused earlier using pause() function. Should be called after pause.

stop

This function will stop benchmarking. Should be called after start or resume.

This function will print benchmark result in tablur form. Below is example:

Start Datetime: Sep 28 2013 21:57:06
End Datetime: Sep 28 2013 21:57:06
Iteration                         Second         Microsecond    Total in Microseconds
===========================================================================================
START                         1380385626              561582         1380385626561582
PAUSE0                        1380385626              562029         1380385626562029
RESUME0                       1380385626              562058         1380385626562058
PAUSE1                        1380385626              562274         1380385626562274
RESUME1                       1380385626              562290         1380385626562290
END                           1380385626              562520         1380385626562520
===========================================================================================
Total time taken: 0 seconds 893 microseconds
get_benchmark

This function will return anonymous hash reference of benchmark result. Below is an example:

{
  'START_DATETIME' => 'Sep 28 2013 21:57:06',
  'PAUSECOUNT' => 2,
  'TAKEN_MICROSEC' => 893,
  'PAUSE2' => {},
  'RESUMECOUNT' => 2,
  'END_MICROSEC' => 562520,
  'RESUME0' => {
                 'START_SEC' => 1380385626,
                 'START_MICROSEC' => 562058
               },
  'PAUSE0' => {
                'START_SEC' => 1380385626,
                'START_MICROSEC' => 562029
              },
  'END_SEC' => 1380385626,
  'TAKEN_SEC' => '0',
  'END_DATETIME' => 'Sep 28 2013 21:57:06',
  'START_SEC' => 1380385626,
  'PAUSE1' => {
                'START_SEC' => 1380385626,
                'START_MICROSEC' => 562274
              },
  'RESUME1' => {
                 'START_SEC' => 1380385626,
                 'START_MICROSEC' => 562290
               },
  'START_MICROSEC' => 561582
};

AUTHOR

Vipin Singh, <qwer@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2013 by Vipin Singh

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.