php計算函數(shù)執(zhí)行時間的方法

字號:


    這篇文章主要介紹了php計算函數(shù)執(zhí)行時間的方法,以md5函數(shù)加密運行時間為例分析了php計算函數(shù)運行時間的技巧,需要的朋友可以參考下
    本文實例講述了php計算函數(shù)執(zhí)行時間的方法。分享給大家供大家參考。具體如下:
    我們可以通過在程序的前后分別記錄開始和結(jié)束時間,兩個時間差就是程序的執(zhí)行時間。
    代碼如下:
    <?php
    $long_str = "this is a test to see how much time md5 function takes to execute over this string";
    // start timing from here
    $start = microtime(true);
    // function to test
    $md5 = md5($long_str);
    $elapsed = microtime(true) - $start;
    echo "That took $elapsed seconds.\n";
    ?>
    運行結(jié)果如下:
    That took 7.1525573730469E-6 seconds.
    希望本文所述對大家的php程序設(shè)計有所幫助。