Php server integer, floating point, data I/O capability test function-PHP source code

Source: Internet
Author: User
The following provides three functions to test the server's integer computing capability test, floating point computing capability test, and data IO capability test. // The following provides three functions to test the server's integer computing capability test, floating point computing capability test, and data IO capability test.

Script ec (2); script

The Code is as follows:
Function test_int ()
{
$ TimeStart = gettimeofday ();
For ($ I = 0; I I <3000000; $ I ++ );
{
$ T = 1 + 1;
}
$ TimeEnd = gettimeofday ();
$ Time = ($ timeEnd ["usec"]-$ timeStart ["usec"])/1000000 + $ timeEnd ["sec"]-$ timeStart ["sec"];
$ Time = round ($ time, 3). "seconds ";
Return $ time;
}

/*--------
Floating Point computing capability test
----------*/

The Code is as follows:
Function test_float ()
{
$ T = pi ();
$ TimeStart = gettimeofday ();
For ($ I = 0; I I <3000000; $ I ++ );
{
Sqrt ($ t );
}
$ TimeEnd = gettimeofday ();
$ Time = ($ timeEnd ["usec"]-$ timeStart ["usec"])/1000000 + $ timeEnd ["sec"]-$ timeStart ["sec"];
$ Time = round ($ time, 3). "seconds ";
Return $ time;
}


/*-----
Test data IO capability
-----*/

The Code is as follows:
Function test_io ()
{
$ Fp = fopen (PHPSELF, "r ");
$ TimeStart = gettimeofday ();
For ($ I = 0; I 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). "seconds ";
Return ($ time );
}


/*
Many companies write related server probe testing tools. We only provide three simple integer operations, floating point operations, and I/O data output stress tests.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.