When I run into performance trouble, I do like this:
use Time::HiRes;
my $ENABLE_PROFILING = 1;
my $exit_genchars_time = 0;
...
sub exit_genchars {
my $temp_time = Time::HiRes::time()
if $ENABLE_PROFILING;
log_event("Exit called\n");
$exit_genchars_time +=
Time::HiRes::time() - $temp_time if $ENABLE_PROFILING;
exit(0);
}
...
sub END {
if ($ENABLE_PROFILING) {
print "Spent " . sprintf("%.2f") .
" seconds inside exit_genchars\n";
...
...
}
}
etc. It ain't very pretty. It's low-tech, not very expensive, fairly easy to remove afterwards, and most of all in my domain: Thread-safe.