cronus has asked for the wisdom of the Perl Monks concerning the following question:

Perl being the magical language it is, I wonder is there a way to evaluate two pieces of code that do the same thing but do it in different ways ? I have two ways to retrieve information from a database and stick it into a HTML template but niether is particularly fast and I'd like to be able to test both for speed to see which to choose. But the principle could be used with any two pieces of different code that produce the same effect. Any ideas ?

Replies are listed 'Best First'.
Re: Measuring Speed
by lhoward (Vicar) on Mar 08, 2001 at 19:31 UTC
    See the Benchmark module for the general solution. It is part of all standard perl distributions.

    If you're interested in testing CGI's against each other you may want to use a program like ab (apache benchmark) to test them so you can see how they perform under higher load: one CGI may be faster running one-at-a-time, but the other may scale better under multiple, concurrent hits.

(kudra: benchmark) Re: Measuring Speed
by kudra (Vicar) on Mar 08, 2001 at 19:35 UTC
    You are probably looking for Benchmark. The documentation should give you most of the information you need, or you can try searching for other questions concerning benchmark.
Re: Measuring Speed
by coreolyn (Parson) on Mar 09, 2001 at 19:30 UTC