<?xml version="1.0" encoding="windows-1252"?>
<node id="87263" title="Re: Benchmarking with Memory Profiling" created="2001-06-10 03:46:33" updated="2005-07-28 19:02:56">
<type id="11">
note</type>
<author id="76537">
andreychek</author>
<data>
<field name="doctext">
You're in luck!  There are all sorts of methods to benchmark code.  I found that there are some excellent &lt;a href="http://perl.apache.org/guide/performance.html"&gt;explanations on benchmarking&lt;/a&gt; in the mod_perl guide.&lt;br&gt;&lt;br&gt;

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 [cpan://Benchmark.pm|Benchmark] module, which you already tried.  However, they give other examples using modules like [cpan://Time::HiRes] and [cpan://GTop].  Here is an example of the code you would use with Time::HiRes (copied from the mod_perl guide):

&lt;code&gt;

  use Time::HiRes qw(gettimeofday tv_interval);
 
  my $start_time = [ gettimeofday ];
  sub_that_takes_a_teeny_bit_of_time();
  my $end_time = [ gettimeofday ];
  my $elapsed = tv_interval($start_time,$end_time);
  
  print "The sub took $elapsed seconds."

&lt;/code&gt;

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.&lt;br&gt;&lt;br&gt;

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.&lt;br&gt;
  -Eric</field>
<field name="root_node">
87256</field>
<field name="parent_node">
87256</field>
</data>
</node>
