diff --git a/bench.php b/bench.php
index 928de94..9abca7b 100644
--- a/bench.php
+++ b/bench.php
@@ -9,8 +9,8 @@
# Company : Code24 BV, The Netherlands #
# Author : Sergey Dryabzhinsky #
# Company : Rusoft Ltd, Russia #
-# Date : Aug 08, 2018 #
-# Version : 1.0.32 #
+# Date : MAy 01, 2019 #
+# Version : 1.0.33 #
# License : Creative Commons CC-BY license #
# Website : https://github.com/rusoft/php-simple-benchmark-script #
# Website : https://git.rusoft.ru/open-source/php-simple-benchmark-script #
@@ -18,20 +18,34 @@
################################################################################
*/
-$scriptVersion = '1.0.32';
+$scriptVersion = '1.0.33';
+
+ini_set('display_errors', 0);
+ini_set('error_log', null);
+error_reporting(E_ERROR | E_WARNING | E_PARSE);
+// Disable explicit error reporting
+$xdebug = ini_get('xdebug.default_enable');
+ini_set('xdebug.show_exception_trace', 0);
+
+if ($xdebug) {
+ print('
<<< ERROR >>> You need to disable Xdebug extension! It greatly slow things down!
'.PHP_EOL);
+ exit(1);
+}
// Used in hacks/fixes checks
$phpversion = explode('.', PHP_VERSION);
$dropDead = false;
+// No php < 4
if ((int)$phpversion[0] < 4) {
$dropDead = true;
}
+// No php <= 4.3
if ((int)$phpversion[0] == 4 && (int)$phpversion[1] < 3) {
$dropDead = true;
}
if ($dropDead) {
- print('<<< ERROR >>> Need PHP 4.3+! Current version is ' . PHP_VERSION . '
');
+ print('<<< ERROR >>> Need PHP 4.3+! Current version is ' . PHP_VERSION . '
'.PHP_EOL);
exit(1);
}
if (!defined('PHP_MAJOR_VERSION')) {
@@ -41,7 +55,7 @@
define('PHP_MINOR_VERSION', (int)$phpversion[1]);
}
-$stringTest = " the quick brown fox jumps over the lazy dog and eat lorem ipsum
Valar morghulis
\n\rабыр\nвалар дохаэрис ";
+$stringTest = " the quick brown fox jumps over the lazy dog and eat lorem ipsum
Valar morghulis
\n\rабыр\nвалар дохаэрис У нас закончились ложки, Нео! ";
$regexPattern = '/[\s,]+/';
/** ------------------------------- Main Defaults ------------------------------- */
@@ -53,6 +67,8 @@
$recalculateLimits = 1;
+$printDumbTest = 0;
+
$outputTestsList = 0;
$showOnlySystemInfo = 0;
@@ -80,6 +96,13 @@
$recalculateLimits = 0;
}
+if ((int)getenv('PRINT_DUMB_TEST')) {
+ $printDumbTest = 1;
+}
+if (isset($_GET['print_dumb_test']) && (int)$_GET['print_dumb_test']) {
+ $printDumbTest = 1;
+}
+
if ((int)getenv('LIST_TESTS')) {
$outputTestsList = 1;
}
@@ -104,6 +127,7 @@
// http://php.net/manual/ru/function.getopt.php example #2
$shortopts = "h";
$shortopts .= "d";
+$shortopts .= "D";
$shortopts .= "L";
$shortopts .= "I";
$shortopts .= "m:"; // Обязательное значение
@@ -113,6 +137,7 @@
$longopts = array(
"help",
"dont-recalc",
+ "dumb-test-print",
"list-tests",
"system-info",
"memory-limit:", // Обязательное значение
@@ -147,8 +172,9 @@
. PHP_EOL
. ' -h|--help - print this help and exit' . PHP_EOL
. ' -d|--dont-recalc - do not recalculate test times / operations count even if memory of execution time limits are low' . PHP_EOL
+ . ' -D|--dumb-test-print - print dumb test time, for debug purpose' . PHP_EOL
. ' -L|--list-tests - output list of available tests and exit' . PHP_EOL
- . ' -I|--system-info - output system info but do not run tests and exit' . PHP_EOL
+ . ' -I|--system-info - output system info but do not run tests and exit' . PHP_EOL
. ' -m|--memory-limit - set memory_limit value in Mb, defaults to 256 (Mb)' . PHP_EOL
. ' -t|--time-limit - set max_execution_time value in seconds, defaults to 600 (sec)' . PHP_EOL
. ' -T|--run-test - run selected test, test names from --list-tests output, can be defined multiple times' . PHP_EOL
@@ -165,6 +191,7 @@
. PHP_EOL
. ' -h - print this help and exit' . PHP_EOL
. ' -d - do not recalculate test times / operations count even if memory of execution time limits are low' . PHP_EOL
+ . ' -D - print dumb test time, for debug purpose' . PHP_EOL
. ' -L - output list of available tests and exit' . PHP_EOL
. ' -I - output system info but do not run tests and exit' . PHP_EOL
. ' -m - set memory_limit value in Mb, defaults to 256 (Mb)' . PHP_EOL
@@ -192,6 +219,11 @@
$recalculateLimits = 0;
break;
+ case 'D':
+ case 'dumb-test-print':
+ $printDumbTest = 1;
+ break;
+
case 'L':
case 'list-tests':
$outputTestsList = 1;
@@ -265,28 +297,38 @@
/** ---------------------------------- Tests limits - to recalculate -------------------------------------------- */
// Gathered on this machine
-$loopMaxPhpTimesMHz = 3700;
+$loopMaxPhpTimesMHz = 3000;
// How much time needed for tests on this machine
$loopMaxPhpTimes = array(
- '4.4' => 235,
- '5.2' => 150,
- '5.3' => 130,
+ '4.4' => 350,
+ '5.2' => 237,
+ '5.3' => 211,
// 5.4, 5.5, 5.6
- '5' => 130,
+ '5.4' => 191,
+ '5.5' => 189,
+ '5.6' => 190,
// 7.0, 7.1
- '7' => 65,
+ '7.0' => 109,
+ '7.1' => 107,
+ '7.2' => 105,
+ '7.3' => 92,
);
$dumbTestMaxPhpTimes = array(
- '4.4' => 1.3,
- '5.2' => 0.97,
- '5.3' => 0.95,
+ '4.4' => 2.13,
+ '5.2' => 1.82,
+ '5.3' => 1.82,
// 5.4, 5.5, 5.6
- '5' => 0.95,
+ '5.4' => 1.71,
+ '5.5' => 1.86,
+ '5.6' => 1.92,
// 7.0, 7.1
- '7' => 0.58,
+ '7.0' => 1.19,
+ '7.1' => 1.19,
+ '7.2' => 1.18,
+ '7.3' => 1.05,
);
$testsLoopLimits = array(
- '01_math' => 1400000,
+ '01_math' => 1000000,
// Nice dice roll
// That limit gives around 256Mb too
'02_string_concat' => 7700000,
@@ -304,23 +346,47 @@
'12_unserialize' => 1300000,
'13_array_loop' => 200,
'14_array_loop' => 200,
- '15_loops' => 190000000,
- '16_loop_ifelse' => 90000000,
- '17_loop_ternary' => 90000000,
+ '15_loops' => 100000000,
+ '16_loop_ifelse' => 50000000,
+ '17_loop_ternary' => 50000000,
'18_1_loop_def' => 20000000,
'18_2_loop_undef' => 20000000,
- '19_type_func' => 5000000,
- '20_type_conv' => 5000000,
+ '19_type_func' => 3000000,
+ '20_type_conv' => 3000000,
'21_loop_except' => 4000000,
'22_loop_nullop' => 50000000,
'23_loop_spaceship' => 50000000,
'24_xmlrpc_encode' => 200000,
'25_xmlrpc_decode' => 30000,
+ '26_1_public' => 5000000,
+ '26_2_getset' => 5000000,
+ '26_3_magic' => 5000000,
);
$totalOps = 0;
/** ---------------------------------- Common functions -------------------------------------------- */
+/**
+ * Gt pretty OS release name, if available
+ */
+function get_current_os()
+{
+ $osFile = '/etc/os-release';
+ $result = PHP_OS;
+ if (file_exists($osFile)) {
+ $f = fopen($osFile, 'r');
+ while (!feof($f)) {
+ $line = trim(fgets($f, 1000000));
+ if (strpos($line, 'PRETTY_NAME=') === 0) {
+ $s = explode('=', $line);
+ $result = array_pop($s);
+ $result = str_replace('"','', $result);
+ }
+ }
+ }
+ return $result;
+}
+
function get_microtime()
{
$time = microtime(true);
@@ -658,7 +724,9 @@ function mymemory_usage()
// TIME WASTED HERE
$dumbTestTime = dumb_test_Functions();
// Debug
-// print($dumbTestTime);
+ if ($printDumbTest) {
+ print("Dumb test time: " .$dumbTestTime . PHP_EOL);
+ }
if ($dumbTestTime > $dumbTestTimeMax) {
$factor *= 1.0 * $dumbTestTimeMax / $dumbTestTime;
}
@@ -1394,6 +1462,7 @@ function test_25_XmlRpc_Decode()
. str_pad("Start", $padInfo) . " : " . date("Y-m-d H:i:s") . "\n"
. str_pad("Server", $padInfo) . " : " . php_uname('s') . '/' . php_uname('r') . ' ' . php_uname('m') . "\n"
. str_pad("Platform", $padInfo) . " : " . PHP_OS . "\n"
+ . str_pad("System", $padInfo) . " : " . get_current_os() . "\n"
. str_pad("CPU", $padInfo) . " :\n"
. str_pad("model", $padInfo, ' ', STR_PAD_LEFT) . " : " . $cpuInfo['model'] . "\n"
. str_pad("cores", $padInfo, ' ', STR_PAD_LEFT) . " : " . $cpuInfo['cores'] . "\n"
diff --git a/php5.inc b/php5.inc
index 2cf164f..9fd9fe5 100644
--- a/php5.inc
+++ b/php5.inc
@@ -1,24 +1,71 @@
number;
+ }
+
+ public function setNumber($new)
+ {
+ $this->number = $new;
+ return $this;
+ }
+}
+
+class MagicMethods
+{
+ private $number = 0;
+
+ public function __get($name)
+ {
+ if ($name === 'number') {
+ return $this->number;
+ }
+ return null;
+ }
+
+ public function __set($name, $new)
+ {
+ if ($name === 'number') {
+ $this->number = $new;
+ }
+ }
+}
+
+/* ------------------------ Tests ------------------------ */
+
function test_21_0_Loop_Exception_None()
{
- global $testsLoopLimits;
+ global $testsLoopLimits, $totalOps;
$count = $testsLoopLimits['21_loop_except'];
$time_start = get_microtime();
for ($i = 0; $i < $count; $i++) {
$a = $i;
}
+ $totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
function test_21_1_Loop_Exception_Try()
{
- global $testsLoopLimits;
+ global $testsLoopLimits, $totalOps;
$count = $testsLoopLimits['21_loop_except'];
$time_start = get_microtime();
@@ -28,12 +75,13 @@ function test_21_1_Loop_Exception_Try()
} catch (Exception $e) {
}
}
+ $totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
function test_21_2_Loop_Exception_Catch()
{
- global $testsLoopLimits;
+ global $testsLoopLimits, $totalOps;
$count = $testsLoopLimits['21_loop_except'];
$time_start = get_microtime();
@@ -44,5 +92,58 @@ function test_21_2_Loop_Exception_Catch()
} catch (Exception $e) {
}
}
+ $totalOps += $count;
+ return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
+}
+
+function test_26_1_Class_Public_Properties()
+{
+ global $testsLoopLimits, $totalOps;
+
+ $c = new PublicProperties();
+ $r = 0;
+
+ $count = $testsLoopLimits['26_1_public'];
+ $time_start = get_microtime();
+ for ($i = 0; $i < $count; $i++) {
+ $r = $c->number;
+ $c->number = $r + $i;
+ }
+ $totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
+
+function test_26_2_Class_Getter_Setter()
+{
+ global $testsLoopLimits, $totalOps;
+
+ $c = new GetterSetter();
+ $r = 0;
+
+ $count = $testsLoopLimits['26_2_getset'];
+ $time_start = get_microtime();
+ for ($i = 0; $i < $count; $i++) {
+ $r = $c->getNumber();
+ $c->setNumber($r + $i);
+ }
+ $totalOps += $count;
+ return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
+}
+
+function test_26_3_Class_Magic_Methods()
+{
+ global $testsLoopLimits, $totalOps;
+
+ $c = new MagicMethods();
+ $r = 0;
+
+ $count = $testsLoopLimits['26_3_magic'];
+ $time_start = get_microtime();
+ for ($i = 0; $i < $count; $i++) {
+ $r = $c->number;
+ $c->number = $r + $i;
+ }
+ $totalOps += $count;
+ return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
+}
+
diff --git a/php7.inc b/php7.inc
index b56923b..6708781 100644
--- a/php7.inc
+++ b/php7.inc
@@ -5,7 +5,7 @@
function test_22_Loop_Null_Op()
{
- global $testsLoopLimits;
+ global $testsLoopLimits, $totalOps;
$a = array(0 => 0, 2 => 2, 4 => 4);
@@ -14,17 +14,19 @@ function test_22_Loop_Null_Op()
for ($i = 0; $i < $count; $i++) {
$r = $a[$i % 2] ?? 0;
}
+ $totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}
function test_23_Loop_Spaceship_Op()
{
- global $testsLoopLimits;
+ global $testsLoopLimits, $totalOps;
$count = $testsLoopLimits['23_loop_spaceship'];
$time_start = get_microtime();
for ($i = 0; $i < $count; $i++) {
$r = $i % 5 <=> 2;
}
+ $totalOps += $count;
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
}