Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Perl CGI question

Options
  • 19-07-2003 4:24pm
    #1
    Registered Users 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 Posts: 68,317 ✭✭✭✭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 Posts: 605 ✭✭✭exiztone


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


Advertisement