Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Execution Time

  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    132
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question Execution Time

    I have searched all over the net about: calculating php execution time (of all My page) and found many many and many ways to do it...

    But what is the best correct and accurate way? (to calculate php (total) execution time of a page)

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Easiest and works just the same as every other way
    PHP Code:
    <?php

    $start 
    microtime(true);
    /*
        source code here
    */
    $end microtime(true);

    echo 
    "Page took " .($end $start). " seconds to execute";

    ?>

  • #3
    Regular Coder
    Join Date
    Jun 2010
    Posts
    132
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by Nightfire View Post
    Easiest and works just the same as every other way
    PHP Code:
    <?php

    $start 
    microtime(true);
    /*
        source code here
    */
    $end microtime(true);

    echo 
    "Page took " .($end $start). " seconds to execute";

    ?>
    Thanks. But I am now really confused between whether to use the code above or the code at http://www.developerfusion.com/code/...n-time-in-php/ (someone told Me it's the most accurate...)

    Is there is any difference between the two?

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Don't know tbh, to me it looks like they do exactly the same thing. They're both using microtime which is showing by microseconds (0.000000000000001 seconds)

  • #5
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Yeah, the two are identical... except I would guess using microtime( TRUE ) is faster than using microtime() and converting the string value to a float, as microtime( TRUE ) already returns a float... so no parsing is necessary.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    microtime(true) is a newer feature as of 5.0. Prior to this, you had to split off the msec and sec from the string by exploding it. If you're on a newer system, microtime(true) is a lot easier to do and theoretically faster than just a microtime().

    In other words, the link you have is to old code, which btw is perfectly good code to use even as of today.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •