Web Analytics Made Easy -
StatCounter Execution Time - CodingForum

Announcement

Collapse
No announcement yet.

Execution Time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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";

    ?>

    Comment


    • #3
      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?

      Comment


      • #4
        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)

        Comment


        • #5
          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.
          ZCE

          Comment


          • #6
            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.
            PHP Code:
            header('HTTP/1.1 420 Enhance Your Calm'); 
            Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

            Comment

            Working...
            X