PHP code execution time

后端 未结 9 954
既然无缘
既然无缘 2021-02-14 14:13

How to find my code execution time?

I am using the below snippet.

I am not happy with that?

list ($msec, $sec) = explode(\' \', microtime());
$mi         


        
相关标签:
9条回答
  • 2021-02-14 14:37

    Thanks for sharing your information.

    The below one also LITTLE BIT near of my solution.

    function microtime_float() {
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }
    
    $time_start = microtime_float();
    
    SOURCE CODE
    
    $time_end = microtime_float();
    $time = round($time_end - $time_start, 4);
    
    echo "Last uncached content render took $time seconds";
    
    0 讨论(0)
  • 2021-02-14 14:40

    In LINUX:

    For one simple code:

    time php -r "echo 'hello';"

    output:

    hello
    real 0m0.095s
    user 0m0.033s
    sys 0m0.055s

    For a php file:

    time php hello.php

    output:

    hello
    real 0m0.073s
    user 0m0.025s
    sys 0m0.047s

    0 讨论(0)
  • 2021-02-14 14:40
    <?php
    // Randomize sleeping time
    usleep(mt_rand(100, 10000));
    
    // As of PHP 5.4.0, REQUEST_TIME_FLOAT is available in the $_SERVER superglobal array.
    // It contains the timestamp of the start of the request with microsecond precision.
    $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
    
    echo "Did nothing in $time seconds\n";
    ?>
    
    0 讨论(0)
提交回复
热议问题