php 服务器整数,浮点,数据IO能力测试函数
php教程 服务器整数,浮点,数据IO能力测试函数
//下面提供一三个针对函数来测试服务器的整数运算能力测试, 浮点运算能力测试和数据IO能力测试哦。
function test_int()
{
$timeStart = gettimeofday();
for($i = 0; $i < 3000000; $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 < 3000000; $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 < 10000; $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数据输出压力测试。
补充:Php教程,Php常用代码