How to use bench mark module for sub routines in perl?

Hi,

I have 2 sub routines for example.

use Benchmark 'cmpthese';

sub explicit {
print "\n print and calculate\n";
}

sub new_per_loop {
     for (0..4){
print "\n print the loop \n";
    }
}

cmpthese (10_000, {
                 'Explicit'           => &explicit,
                 'New Array Per Loop' => &new_per_loop,
                            }
      );

It is going to an infinite loop and cmpthese function what should be the count?

What is the default count?

I tried to understand through Google but i did not get a clear picture?

In the real scenario i have to apply bench mark and calculate the time taken for a bigger sub routine which has many loops.

How can i put this bench mark to calculate the time taken by the sub routine?

If u can provide me the clear picture with an example that would be really great.

Regards
vanitha

Not that I know PERL much, but Benchmark - perldoc.perl.org says:
cmpthese - print results of timethese as a comparison chart
and:

    # cmpthese can be used both ways as well
    cmpthese($count, {
'Name1' => '...code1...',
'Name2' => '...code2...',
    });
 
    cmpthese($count, {
'Name1' => sub { ...code1... },
'Name2' => sub { ...code2... },
    });
 
    # ...or in two stages
    $results = timethese($count, 
        {
    'Name1' => sub { ...code1... },
    'Name2' => sub { ...code2... },
        },
'none'
    );
    cmpthese( $results ) ;

I suggest the first form with no & and in single quotes.

HI,

I tried these but could not get the results.

I have to identify the sub routine which is taking a lot of time.

But i am unable to trace which part of the sub routine.

If u can help me out with this that would be really great.

REgards