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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Perl CGI question

  • 19-07-2003 3: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,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, Registered Users 2 Posts: 605 ✭✭✭exiztone


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


Advertisement