NAME
Benchmark::Object - Simple interface to do benchmarking.
SYNOPSIS
use Benchmark::Object;
print "Benchmarking for loop runs 2000 times.\n";
#Sart benchmarking here
my $obj = Benchmark::Object->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.
- print_benchmark
-
This function will print benchmark result in tablur form. Below is example:
Start Datetime: Oct 14 2013 15:27:36 End Datetime: Oct 14 2013 15:27:36 Iteration Second Microsecond Total in Microseconds =========================================================================================== START 1381744656 838024 1.381745e+015 PAUSE0 1381744656 838417 1.381745e+015 RESUME0 1381744656 838435 1.381745e+015 PAUSE1 1381744656 838640 1.381745e+015 RESUME1 1381744656 838651 1.381745e+015 END 1381744656 838851 1.381745e+015 =========================================================================================== Total time taken: 0 seconds 798 microseconds
- get_benchmark
-
This function will return anonymous hash reference of benchmark result. Below is an example:
{ 'START_DATETIME' => 'Oct 14 2013 15:27:36', 'PAUSECOUNT' => 2, 'TAKEN_MICROSEC' => 798, 'PAUSE2' => {}, 'RESUMECOUNT' => 2, 'END_MICROSEC' => 838851, 'RESUME0' => { 'START_SEC' => 1381744656, 'START_MICROSEC' => 838435 }, 'PAUSE0' => { 'START_SEC' => 1381744656, 'START_MICROSEC' => 838417 }, 'END_SEC' => 1381744656, 'TAKEN_SEC' => '0', 'END_DATETIME' => 'Oct 14 2013 15:27:36', 'START_SEC' => 1381744656, 'PAUSE1' => { 'START_SEC' => 1381744656, 'START_MICROSEC' => 838640 }, 'RESUME1' => { 'START_SEC' => 1381744656, 'START_MICROSEC' => 838651 }, 'START_MICROSEC' => 838024 }
AUTHOR
Vipin Singh, <qwer@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2013 by Vipin Singh
This library is free and with no warranty. You can redistribute it and/or modify it under the same terms as Perl itself.