/** * Number of file operations. * @return array * @static * @final */ public static final function NumberFileOperations() { if (FileSystem::FolderDeletion() === false || FileSystem::FileDeletion() === false) { return false; } if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_operations")) { for ($j = 0; $j < 100; $j++) { @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_operations/test_file_{$j}.php"); } @rmdir("{$_SERVER['DOCUMENT_ROOT']}/test_operations"); } $operations = array(); @mkdir("{$_SERVER['DOCUMENT_ROOT']}/test_operations"); $fileName = "{$_SERVER['DOCUMENT_ROOT']}/test_operations/test_file_#j#.php"; $body = "<?\$a='" . str_repeat("q", 1024) . "';?><?/*" . str_repeat("w", 1024) . "*/?><?\$b='" . str_repeat("e", 1024) . "';?>"; for ($i = 0; $i < 4; $i++) { $time = Tools::getTime(); for ($j = 0; $j < 100; $j++) { $file = str_replace("#j#", $j, $fileName); } $firstResult = Tools::getTime() - $time; $time = Tools::getTime(); for ($j = 0; $j < 100; $j++) { $file = str_replace("#j#", $j, $fileName); $fileRes = @fopen($file, "wb"); @fwrite($fileRes, $body); @fclose($fileRes); @(include $file); @unlink($file); } $secondResult = Tools::getTime() - $time; if ($secondResult > $firstResult) { $operations[] = 100 / ($secondResult - $firstResult); } } if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_operations")) { for ($j = 0; $j < 100; $j++) { @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_operations/test_file_{$j}.php"); } @rmdir("{$_SERVER['DOCUMENT_ROOT']}/test_operations"); } return array('value' => number_format(count($operations) > 0 ? array_sum($operations) / (double) count($operations) : 0, 1, '.', ''), 'postfix' => 'FOPS'); }
/** * Speed test select 1000 records. * @return array|boolean * @final */ public final function SpeedSelect() { if ($this->MyIsam()) { $type = 'MYISAM'; } elseif ($this->Innodb()) { $type = 'InnoDB'; } else { return false; } $result = false; $table = $this->db->prepare("CREATE TABLE test_table (test varchar(100), test2 varchar(50), test3 varchar(30), test4 text) ENGINE={$type}"); if ($table->execute()) { $time = Tools::getTime(); for ($i = 0; $i < 1000; $i++) { $insert = $this->db->prepare("INSERT INTO test_table VALUES ('test1','test2','test3','test4')"); if ($insert->execute() == false) { return false; } } $time = Tools::getTime(); $select = $this->db->prepare("SELECT * FROM test_table"); if ($select->execute() == false) { return false; } $result = array('value' => round(1000 / (Tools::getTime() - $time)), 'postfix' => 'q/sec.'); $table = $this->db->prepare('DROP TABLE IF EXISTS test_table;'); $table->execute(); } return $result; }
/** * Checking the time required to create the file. * @param integer $files * @return array * @static * @final */ public static final function TimeToCreateFile($files = 1000) { if (self::FolderDeletion() === false || self::FileDeletion() === false) { return false; } if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_time")) { for ($i = 0; $i < $files; $i++) { @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_time/test_file_{$i}"); } @rmdir("{$_SERVER['DOCUMENT_ROOT']}/test_time"); } @mkdir("{$_SERVER['DOCUMENT_ROOT']}/test_time"); $time = Tools::getTime(); for ($i = 0; $i < $files; $i++) { $file = @fopen("{$_SERVER['DOCUMENT_ROOT']}/test_time/test_file_{$i}", 'wb'); @fwrite($file, '<?php #Hello, test! ?>'); @fclose($file); if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_time/test_file_{$i}") == false) { continue; } } $result = round(Tools::getTime() - $time, 2); if (file_exists("{$_SERVER['DOCUMENT_ROOT']}/test_time")) { for ($i = 0; $i < $files; $i++) { @unlink("{$_SERVER['DOCUMENT_ROOT']}/test_time/test_file_{$i}"); } @rmdir("{$_SERVER['DOCUMENT_ROOT']}/test_time"); } return array('value' => $result, 'postfix' => 's'); }