CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Benchmarking count



Jul 22, 2013, 8:35 PM

Post #1 of 4 (2051 views)
Benchmarking count Can't Post

Hi, ive been looking over multiple examples of benchmarking code using cmpthese function and i noticed a lot of people using negative numbers as part of their $count.

What is the difference between using something like -5 as the count and 1000 as the count?

Thanks in advance for any help.


Jul 24, 2013, 10:45 AM

Post #2 of 4 (2040 views)
Re: [anglaissam] Benchmarking count [In reply to] Can't Post


Veteran / Moderator

Jul 24, 2013, 1:42 PM

Post #3 of 4 (2034 views)
Re: [anglaissam] Benchmarking count [In reply to] Can't Post

If you look at the code, you'll see that cmpthese calls timethis which expects the count param to be 0 or a negative number. The module documentation states:

The COUNT can be zero or negative: this means the minimum number of CPU seconds to run. A zero signifies the default of 3 seconds.

If you pass a number greater than 0, the function will call the timeit() function, which accepts positive numbers, else it will call the countit() function.

The module's documentation doesn't go into the details about the differences between the positive/negative counts. This is one example where it's a good idea to look over the source code to see what it's doing. I've skimmed over it, but haven't reviewed it enough to get a clear understanding of the differences in the count param in each function.


Jul 24, 2013, 3:17 PM

Post #4 of 4 (2031 views)
Re: [FishMonger] Benchmarking count [In reply to] Can't Post

Based on what you told me Fishmonger, combined with a little experimentation, it seems that the function names give away exactly how the count param works.

Negative numbers call countit(). Ie if we set count to -60, it will go through each code being benchmarked approximately 60 cpu seconds and "count" how many loops it has made.

Positive numbers as you said call timeit(). if the count is set to 1000 then it will time how long it takes to go through 1000 loops of each code.

I could be wrong but a few minutes of experimentation seem to support this.

Thanks for your help Fishmonger


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives