duanrong5927 2013-11-15 12:36
浏览 96
已采纳

检查PHP函数的服务器运行时和Internet流量

I want to consult you.

I want to build a 'testing code' of PHP functions, that will chek which function is better.

the 'testing code' need to check:

  • how much time (at milliseconds) its take to the server to run the function.
  • how much internet traffic the function will use.

someone have any idea how could i check this things?

  • 写回答

2条回答 默认 最新

  • duanhui5344 2013-11-15 12:44
    关注

    What I understand is that you want to do a benchmark.

    To know how much time a function needs, you can do it with this function :

    function microtime_float()
    {
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }
    $timeStart = microtime_float();
    // your function
    $timeEnd = microtime_float();
    echo $timeEnd - $timeStart , ' seconds.';
    

    The advantage of this function is that you will obtain a result in miliseconds, so it will be way more precise than a timestamp.

    I would advise you to execute the function in a loop to obtain an average time, and to be more accurate.

    For the network traffic, I think the simplest is to count the number of bytes you send, and the number of byte you receive. In case of a curl for example, it should be pretty straigh forward.

    I hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大