You're in luck! There are all sorts of methods to benchmark code. I found that there are some excellent explanations on benchmarking
in the mod_perl guide.
While the mod_perl guide does talk about mod_perl, much of the information there is relevant to all Perl uses. The first example of benchmarking they give uses the Benchmark
module, which you already tried. However, they give other examples using modules like Time::HiRes
. Here is an example of the code you would use with Time::HiRes (copied from the mod_perl guide):
use Time::HiRes qw(gettimeofday tv_interval);
my $start_time = [ gettimeofday ];
my $end_time = [ gettimeofday ];
my $elapsed = tv_interval($start_time,$end_time);
print "The sub took $elapsed seconds."
But the good, juicy information doesn't stop there. They get into code profiling, memory usage, and other goodies -- including the speed differences between method calls vs function calls, along with offering various advice on good coding habits to reduce memory usage.
Feel free to skip any sections that are mod_perl/web specific, if that isn't what you intend to do. Again though, much of what they offer there goes for any code, not just mod_perl and web applications.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||