package Sources::Benchmark; use strict; use warnings; use Benchmark; use Sources::Global; my $m_start = 0; my $m_end = 0; my $m_enabled = 1; sub is_enabled { return $m_enabled; } sub enable { $m_enabled = 1; 1; } sub disable { $m_enabled = 0; 1; } sub start { $m_start = new Benchmark; } sub end { $m_end = new Benchmark; } sub show_stat { my ($obj) = @_; my $tpl = Sources::Global::template_createobject('benchmark.stat.tpl'); my $delta = Benchmark::timediff($m_end, $m_start); $delta = Benchmark::timestr($delta); $delta =~ /(\d+)\s*wallclock secs \(\s*?(\d*?\.\d*?)\s*usr\s*\+\s*(\d*?\.\d*?)\s*sys\s*=\s*(\d*?\.\d*?)\s*cpu/i; $tpl->param('BENCHMARK_EXEC_TIME' => ($1 < 1 ? "Less than 1 sec." : "$1 second(s)")); $tpl->param('BENCHMARK_USR_TIME' => $2); $tpl->param('BENCHMARK_SYS_TIME' => $3); $tpl->param('BENCHMARK_CPU_TIME' => $4); $tpl->param('BENCHMARK_CURRENT_TIME' => time); print $tpl->output; } 1;