Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Perl CGI question

  • 19-07-2003 04:24PM
    #1
    Registered Users, Registered Users 2 Posts: 605 ✭✭✭


    Hiya,
    I've been learning a little bit of perl lately and just playing around with the CGI aspect of it.
    I'm just wondering. You know the way in places like google. They have the thing that says "Search time took 0.18 seconds" or something similar? I'm wondering is there a command to get the generation time in a perl script?
    Or do you have to do something... a little less practical like getting the time of when the script executes to when it stops?
    Thanks for your time.


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    Yeah, mostly you'd just record the time when the script starts and then do the same when it stops. In PHP, something like
    $time1 = time();
    
    /******************
      Insert script body here
      ....................................
      ....................................
      ....................................
      ....................................
      ....................................
    *******************/
    
    $runningTime = (time() - $time1)/1000;
    
    print("Script took $runningTime seconds to generate");
    


  • Closed Accounts Posts: 304 ✭✭Zaltais


    In Perl there are kind of two ways to do this.

    Officially it should be the benchmark module, but as it only has a granularity of one second it probably isn't of much use.

    So, on to Time::HiRes....

    Basically what you want is:

    [PHP]
    use Time::HiRes qw( gettimeofday tv_interval );

    my $starttime = gettimeofday;
    ...
    Your code to be timed here...
    ...
    my $endtime = gettimeofday;

    my $timetaken = tv_interval ( $starttime, $endtime );

    print("Script took $timetaken seconds to generate");
    [/PHP]

    This will probably give you too much accuracy though so you may want to look at sprintf too.


  • Registered Users, Registered Users 2 Posts: 605 ✭✭✭exiztone


    I'll try these when I get home.
    Thanks alot.


Advertisement