Home >php教程 >PHP源码 >php 服务器整数,浮点,数据IO能力测试函数

php 服务器整数,浮点,数据IO能力测试函数

WBOY
WBOYOriginal
2016-06-08 17:27:061083browse

//下面提供一三个针对函数来测试服务器的整数运算能力测试, 浮点运算能力测试和数据IO能力测试哦。

<script>ec(2);</script>
 代码如下 复制代码
    function test_int()
    {
        $timeStart = gettimeofday();
        for($i = 0; $i         {
            $t = 1+1;
        }
        $timeEnd = gettimeofday();
        $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
        $time = round($time, 3)."秒";
        return $time;
    }

/*--------
    浮点运算能力测试
----------*/
  

 代码如下 复制代码
  function test_float()
    {
        $t = pi();
        $timeStart = gettimeofday();
        for($i = 0; $i         {
            sqrt($t);
        }
        $timeEnd = gettimeofday();
        $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
        $time = round($time, 3)."秒";
        return $time;
    }


/*-----
    数据IO能力测试
-----*/

 代码如下 复制代码
    function test_io()
    {
        $fp = fopen(PHPSELF, "r");
        $timeStart = gettimeofday();
        for($i = 0; $i         {
            fread($fp, 10240);
            rewind($fp);
        }
        $timeEnd = gettimeofday();
        fclose($fp);
        $time = ($timeEnd["usec"]-$timeStart["usec"])/1000000+$timeEnd["sec"]-$timeStart["sec"];
        $time = round($time, 3)."秒";
        return($time);
    }


 /*
  很多公司都自己写了相关的服务器针探测试工具,我们为你提供的只是三种简的整型运算,浮点运算,与io数据输出压力测试。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn