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

Hello Monks , Can someone tell me if there is a way to calculate the time that each of your script takes to finish processing somthing ? I mean module or a way if doing it with in the script to print out the time it took runing once it finishs. thanks for help.

Replies are listed 'Best First'.
Re: calculting time
by jeffa (Bishop) on Feb 05, 2004 at 21:42 UTC
Re: calculting time
by Zaxo (Archbishop) on Feb 05, 2004 at 21:43 UTC

    Benchmark is handy. Time::HiRes is accurate - you'd need to grab time at the start and the end and subtract, or else use an interval timer.

    After Compline,
    Zaxo

Re: calculting time
by coreolyn (Parson) on Feb 05, 2004 at 21:47 UTC
Re: calculting time
by dthacker (Deacon) on Feb 05, 2004 at 21:44 UTC
    If you're on linux or unix check the man pages for  time

    Dave
    Code On!
Re: calculting time
by mildside (Friar) on Feb 05, 2004 at 23:30 UTC
    If calculating the elapsed time to the nearest second is accurate enough for you, then a simple solution is to put this line at the end of your script:

    print "Script executed in ", time - $^T, " seconds";

    Hope this helps.

    Cheers!

      what if you want to do minute ,, do you change the - option . I just can't find the a man for time. thanks
        No, that is a minus sign, not an option. I'm subtracting the time the script started from the current time (in seconds). If you want minutes instead, you could simply divide that by sixty. Check time for the doco.

        Cheers!

Re: calculting time
by parkprimus (Sexton) on Feb 05, 2004 at 22:54 UTC
    Type at a unix prompt: time perl name_of_you_prog.pl
    This will give you real, user and sys time.