Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Subroutine execution time

by santosh_vjit (Novice)
on Dec 24, 2010 at 11:18 UTC ( [id://879020]=perlquestion: print w/replies, xml ) Need Help??

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

Hi friends,

I have nearly 100 events which tirgger for every 2- 10mins range i need to calculate execution time of each event and how many times it triggerd

sub test { my $start_time = time; print USAGE_FH "\n".$IP.",$event_name,".$start_time.","; ----------- code for execution ----------- my $endtime = time; my $diff_time = $endtime - $start_time; print USAGE_FH $endtime.",".$difftime; }
This is not helping my cause Can any one please help me

Replies are listed 'Best First'.
Re: Subroutine execution time
by chromatic (Archbishop) on Dec 24, 2010 at 17:20 UTC

    If you need this information to profile and optimize your program, use Devel::NYTProf.

    If you need this information to display statistics while your program runs (or something similar), use Time::HiRes:

    use Time::HiRes qw( gettimeofday tv_interval ); my $t0 = [gettimeofday()]; ... my $elapsed = tv_interval( $tv );
Re: Subroutine execution time
by afoken (Chancellor) on Dec 24, 2010 at 11:52 UTC

    Devel::NYTProf?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Subroutine execution time
by Bor (Beadle) on Dec 24, 2010 at 12:13 UTC
    IMHO you need:
    perldoc Benchmark
Re: Subroutine execution time
by JavaFan (Canon) on Dec 24, 2010 at 11:51 UTC
    Why is it not helping? What do you want it to do different than it is doing now?
Re: Subroutine execution time
by tomfahle (Priest) on Dec 25, 2010 at 08:17 UTC

    Try Devel::DProf - a profiler specialised on subroutine execution times.

    Step 1: Profile the code:

    $ perl -d:DProf yourprog.pl

    Step 2: Display results:

    $ dprofpp -l tmon.out

    Otherwise, use Devel::NYTProf as already suggested.

    HTH,
    Thomas

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://879020]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-03-28 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found