//下面提供一三个针对函数来测试服务器的整数运算能力测试, 浮点运算能力测试和数据IO能力测试哦。
代码如下 | 复制代码 |
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数据输出压力测试。