in reply to Re: Question about benchmarking
in thread Question about benchmarking
to read the POD for the module. If you have a somewhat old and/or broken install (like me), you can always fall back toperldoc Benchmark
:)vi \perl\lib\Benchmark.pm
What you've written is a proper way of using benchmark. Ideally, you would insert several objects into your code to get the times you wanted, but you can do it in a clever and inobtrusive manner:
and then it would be trivial to remove the benchmarking from your production code, either through a command line switch, as above:BEGIN { use Benchmark; my ($oldb, $newb); # inside BEGIN for closure sub mybench { return unless ($opt_b); $newb = new Benchmark; if ($oldb) { # i.e. don't run first time through print timediff($oldb, $newb); } $oldb = $newb; } } Getopt::Std; getopts('b'); mybench(); # some code here mybench(); # some more code here mybench();
or some line in your makefile like:mycode.pl -b
ya know.perl -lne 'print unless /^\s*mybench();/' myscript.pl > production.pl
|
|---|