<?php
$LoopMax = 20000000;
$DateLoopMax = 3000;
$FileReadLoopMax = 2000;
$FileMetaLoopMax = 9000;
$FileCopyLoopMax = 10000;
$EmptyFuncLoopMax = 1500000;
$StringIntLoopMax = 600000;
$EncryptionLoopMax = 2000;
$SysVarArrayLoopMax = 10000;
$StringAssignLoopMax = 7000000;
$ObjectsLoopMax = 350000;
$DBLoopMax = 1000;
$get_as_float = true;
//Set page to reload to itself
if(isset($_SERVER['PHP_SELF'])) {
$filename = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/") + 1);
$PHP_SELF = $_SERVER['PHP_SELF'];
}
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> Empty Loop Tests: ";
echo number_format($LoopMax)." Iterations</td></tr></table><br />";
$StartTime = microtime($get_as_float);
for ($cnt=0; $cnt<$LoopMax; $cnt++)
{
}
echo "<table border='0' width='450px'><tr><td> For Loop</td><td>";
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime) ."<br />";
echo "</td></tr><tr><td> While</td><td>";
$StartTime = microtime($get_as_float);
$cnt = 0;
while ($cnt<$LoopMax) {
$cnt++;
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime) ."<br /></td></tr><tr><td> Do While</td><td>";
$StartTime = microtime($get_as_float);
$cnt = 0;
do
{
$cnt++;
}
while ($cnt<$LoopMax);
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime) ."<br />";
echo "</td></tr></table><br />";
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> String Assignment Tests: ";
echo number_format($StringAssignLoopMax)." Iterations</td></tr></table><br /><table border='0' width='450px'>";
echo "<tr><td> For Loop</td><td>";
$StartTime = microtime($get_as_float);
for ($cnt=0; $cnt<$StringAssignLoopMax; $cnt++)
{
$MyString = "This is a test of string assignment.";
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr><tr><td> While</td><td>";
$StartTime = microtime($get_as_float);
$cnt = 0;
while ($cnt<$StringAssignLoopMax)
{
$MyString = "This is a test of string assignment.";
$cnt++;
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr><tr><td> Do While</td><td>";
$StartTime = microtime($get_as_float);
$cnt = 0;
do
{
$MyString = "This is a test of string assignment.";
$cnt++;
}
while ($cnt<$StringAssignLoopMax);
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr></table><br />";
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> Empty Function Calls: ";
echo number_format($EmptyFuncLoopMax)." Iterations</td></tr></table><br /><table border='0' width='450px'>";
echo "<tr><td> For Loop</td><td>";
$StartTime = microtime($get_as_float);
for ($cnt=0; $cnt<$EmptyFuncLoopMax; $cnt++)
{
EmptyCall();
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr><tr><td> While</td><td>";
$StartTime = microtime($get_as_float);
$cnt = 0;
while ($cnt<$EmptyFuncLoopMax)
{
EmptyCall();
$cnt++;
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr><tr><td> Do While</td><td>";
$StartTime = microtime($get_as_float);
$cnt = 0;
do
{
EmptyCall();
$cnt++;
}
while ($cnt<$EmptyFuncLoopMax);
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
function EmptyCall()
{
}
echo "</td></tr></table><br />";
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> String & Integer Tests: ";
echo number_format($StringIntLoopMax)." Iterations</td></tr></table><br />";
echo "<table border='0' width='450px'><tr><td> For Loop</td><td>";
$StartTime = microtime($get_as_float);
$string1 = 'abcdefghij';
for ($cnt=0; $cnt<$StringIntLoopMax; $cnt++)
{
$x=$cnt * 5;
$x=$x + $x;
$x=$x/10;
$string3 = $string1 . strrev($string1);
$string2 = substr($string1, 9, 1) . substr($string1, 0, 9);
$string1 = strtoupper($string2);
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr></table><br />";
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> Encryption Tests: ";
echo number_format($EncryptionLoopMax)." Iterations</td></tr></table><br />";
echo "<table border='0' width='450px'><tr><td> For Loop</td><td>";
$string2 = "This is a test string to see how fast your web server can process PHP functions";
$StartTime = microtime($get_as_float);
for ($cnt=0; $cnt<$EncryptionLoopMax; $cnt++)
{
$md5 = md5($string2);
$sha1 = sha1($md5);
$crc32 = crc32($sha1);
$cryptDate = crypt($crc32);
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr></table><br />";
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> Date Function Tests: ";
echo number_format($DateLoopMax)." Iterations</td></tr></table><br />";
echo "<table border='0' width='450px'><tr><td> For Loop</td><td>";
$StartTime = microtime($get_as_float);
for ($cnt=0; $cnt<$DateLoopMax; $cnt++)
{
$string3 = date("D M d Y"). ', News Years Day : ' .date("M-d-Y", mktime(0, 0, 0, 1, 1, 1998));
$secNextWeek = time() + (7 * 24 * 60 * 60);
date('Y-m-d', $secNextWeek);
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr></table><br />";
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> SysVar & Array Tests: ";
echo number_format($SysVarArrayLoopMax)." Iterations</td></tr></table><br />";
echo "<table border='0' width='450px'><tr><td> For Loop</td><td>";
$StartTime = microtime($get_as_float);
for ($cnt=0; $cnt<$SysVarArrayLoopMax; $cnt++)
{
$array = $_SERVER;
shuffle($array);
foreach ($array as $value) {
ucfirst($value);
}
arsort($array);
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr></table><br />";
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> File System Tests: ";
echo "</td></tr></table><br />";
echo "<table border='0' width='450px'>";
echo" <tr><td> File Read Loop</td><td>";
$StartTime = microtime($get_as_float);
for ($cnt=0; $cnt<$FileReadLoopMax; $cnt++)
{
//Subtest 1 - reading files
$dataFile = fopen( $filename, "r" ) ;
if($dataFile) {
while (!feof($dataFile)) {
$buffer = fgets($dataFile, 4096);
}
fclose($dataFile);
}
else {
die( "fopen failed for $filename" ) ;
}
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo " (".number_format($FileReadLoopMax)." Iterations)</td></tr>";
echo" <tr><td> Metadata Read Loop</td><td>";
$StartTime = microtime($get_as_float);
for ($cnt=0; $cnt<$FileMetaLoopMax; $cnt++)
{
$filesize = @filesize($filename);
$isreadable = @is_readable($filename);
$iswritable = @is_writable($filename);
$df = @disk_free_space("/");
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo " (".number_format($FileMetaLoopMax)." Iterations)</td></tr>";
echo" <tr><td> File Copy Loop</td><td>";
$file2 = "junk.php";
$StartTime = microtime($get_as_float);
for ($cnt=0; $cnt<$FileCopyLoopMax; $cnt++)
{
$copy = @copy($filename, $file2);
if(!$copy) {
//echo "failed to copy $filename...\n";
} else {
unlink($file2);
}
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo " (".number_format($FileCopyLoopMax)." Iterations)</td></tr>";
echo "</table><br />";
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> Objects Tests: ";
echo number_format($ObjectsLoopMax)." Iterations</td></tr></table><br />";
echo "<table border='0' width='450px'><tr><td> For Loop</td><td>";
$StartTime = microtime($get_as_float);
class Foo {
var $z;
function Foo($var) {
$this->z = $var;
}
function do_foo() {
return $this->z;
}
function multiply($var1, $var2) {
return ($var1 * $var2);
}
}
for ($cnt=0; $cnt<$ObjectsLoopMax; $cnt++)
{
$bar = new Foo("Hello world!");
$_1 = $bar->do_foo();
$_2 = $bar->multiply(72, 12);
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr></table><br />";
//------------------------------------------------------------------------------------------------+
echo "<table border='1' width='450px'><tr><td> DataBase Tests: ";
echo number_format($DBLoopMax)." Iterations</td></tr></table><br />";
echo "<table border='0' width='450px'><tr><td> For Loop</td><td>";
$StartTime = microtime($get_as_float);
/* Specify the server and connection string attributes. */
$serverName = "JHS-WS2008\\SQLEXPRESS"; //JHS-WS2008\SQLEXPRESS
/* Get UID and PWD from application-specific files. */
$uid = "sa";
$pwd = "P@ssw0rd";
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>"perfdata");
for ($cnt=0; $cnt<$DBLoopMax; $cnt++)
{
/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}
/* Query SQL Server for the login of the user accessing the
database. */
$tsql = "SELECT * FROM city";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
/* Iterate through the result set printing a row of data upon each
iteration.*/
while( $row = sqlsrv_fetch_array( $stmt))
{
// echo "City ".$row[0]."</br>";
}
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
}
$EndTime = microtime($get_as_float);
echo ($EndTime - $StartTime);
echo "</td></tr></table><br />";
?>