Skip to content

Commit 96721dc

Browse files
Merge pull request #11 from rusoft/new-tests-class-methods-properties
New test for class magic methods, getters-setters and public properties
2 parents 48ba1f6 + 38adbaa commit 96721dc

File tree

3 files changed

+202
-30
lines changed

3 files changed

+202
-30
lines changed

bench.php

Lines changed: 93 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,43 @@
99
# Company : Code24 BV, The Netherlands #
1010
# Author : Sergey Dryabzhinsky #
1111
# Company : Rusoft Ltd, Russia #
12-
# Date : Aug 08, 2018 #
13-
# Version : 1.0.32 #
12+
# Date : MAy 01, 2019 #
13+
# Version : 1.0.33 #
1414
# License : Creative Commons CC-BY license #
1515
# Website : https://github.com/rusoft/php-simple-benchmark-script #
1616
# Website : https://git.rusoft.ru/open-source/php-simple-benchmark-script #
1717
# #
1818
################################################################################
1919
*/
2020

21-
$scriptVersion = '1.0.32';
21+
$scriptVersion = '1.0.33';
22+
23+
ini_set('display_errors', 0);
24+
ini_set('error_log', null);
25+
error_reporting(E_ERROR | E_WARNING | E_PARSE);
26+
// Disable explicit error reporting
27+
$xdebug = ini_get('xdebug.default_enable');
28+
ini_set('xdebug.show_exception_trace', 0);
29+
30+
if ($xdebug) {
31+
print('<pre><<< ERROR >>> You need to disable Xdebug extension! It greatly slow things down!</pre>'.PHP_EOL);
32+
exit(1);
33+
}
2234

2335
// Used in hacks/fixes checks
2436
$phpversion = explode('.', PHP_VERSION);
2537

2638
$dropDead = false;
39+
// No php < 4
2740
if ((int)$phpversion[0] < 4) {
2841
$dropDead = true;
2942
}
43+
// No php <= 4.3
3044
if ((int)$phpversion[0] == 4 && (int)$phpversion[1] < 3) {
3145
$dropDead = true;
3246
}
3347
if ($dropDead) {
34-
print('<pre><<< ERROR >>> Need PHP 4.3+! Current version is ' . PHP_VERSION . '</pre>');
48+
print('<pre><<< ERROR >>> Need PHP 4.3+! Current version is ' . PHP_VERSION . '</pre>'.PHP_EOL);
3549
exit(1);
3650
}
3751
if (!defined('PHP_MAJOR_VERSION')) {
@@ -41,7 +55,7 @@
4155
define('PHP_MINOR_VERSION', (int)$phpversion[1]);
4256
}
4357

44-
$stringTest = " the quick <b>brown</b> fox jumps <i>over</i> the lazy dog and eat <span>lorem ipsum</span><br/> Valar morghulis <br/>\n\rабыр\nвалар дохаэрис ";
58+
$stringTest = " the quick <b>brown</b> fox jumps <i>over</i> the lazy dog and eat <span>lorem ipsum</span><br/> Valar morghulis <br/>\n\rабыр\nвалар дохаэрис <span class='alert alert-danger'>У нас закончились ложки, Нео!</span> ";
4559
$regexPattern = '/[\s,]+/';
4660

4761
/** ------------------------------- Main Defaults ------------------------------- */
@@ -53,6 +67,8 @@
5367

5468
$recalculateLimits = 1;
5569

70+
$printDumbTest = 0;
71+
5672
$outputTestsList = 0;
5773

5874
$showOnlySystemInfo = 0;
@@ -80,6 +96,13 @@
8096
$recalculateLimits = 0;
8197
}
8298

99+
if ((int)getenv('PRINT_DUMB_TEST')) {
100+
$printDumbTest = 1;
101+
}
102+
if (isset($_GET['print_dumb_test']) && (int)$_GET['print_dumb_test']) {
103+
$printDumbTest = 1;
104+
}
105+
83106
if ((int)getenv('LIST_TESTS')) {
84107
$outputTestsList = 1;
85108
}
@@ -104,6 +127,7 @@
104127
// http://php.net/manual/ru/function.getopt.php example #2
105128
$shortopts = "h";
106129
$shortopts .= "d";
130+
$shortopts .= "D";
107131
$shortopts .= "L";
108132
$shortopts .= "I";
109133
$shortopts .= "m:"; // Обязательное значение
@@ -113,6 +137,7 @@
113137
$longopts = array(
114138
"help",
115139
"dont-recalc",
140+
"dumb-test-print",
116141
"list-tests",
117142
"system-info",
118143
"memory-limit:", // Обязательное значение
@@ -147,8 +172,9 @@
147172
. PHP_EOL
148173
. ' -h|--help - print this help and exit' . PHP_EOL
149174
. ' -d|--dont-recalc - do not recalculate test times / operations count even if memory of execution time limits are low' . PHP_EOL
175+
. ' -D|--dumb-test-print - print dumb test time, for debug purpose' . PHP_EOL
150176
. ' -L|--list-tests - output list of available tests and exit' . PHP_EOL
151-
. ' -I|--system-info - output system info but do not run tests and exit' . PHP_EOL
177+
. ' -I|--system-info - output system info but do not run tests and exit' . PHP_EOL
152178
. ' -m|--memory-limit <Mb> - set memory_limit value in Mb, defaults to 256 (Mb)' . PHP_EOL
153179
. ' -t|--time-limit <sec> - set max_execution_time value in seconds, defaults to 600 (sec)' . PHP_EOL
154180
. ' -T|--run-test <name> - run selected test, test names from --list-tests output, can be defined multiple times' . PHP_EOL
@@ -165,6 +191,7 @@
165191
. PHP_EOL
166192
. ' -h - print this help and exit' . PHP_EOL
167193
. ' -d - do not recalculate test times / operations count even if memory of execution time limits are low' . PHP_EOL
194+
. ' -D - print dumb test time, for debug purpose' . PHP_EOL
168195
. ' -L - output list of available tests and exit' . PHP_EOL
169196
. ' -I - output system info but do not run tests and exit' . PHP_EOL
170197
. ' -m <Mb> - set memory_limit value in Mb, defaults to 256 (Mb)' . PHP_EOL
@@ -192,6 +219,11 @@
192219
$recalculateLimits = 0;
193220
break;
194221

222+
case 'D':
223+
case 'dumb-test-print':
224+
$printDumbTest = 1;
225+
break;
226+
195227
case 'L':
196228
case 'list-tests':
197229
$outputTestsList = 1;
@@ -265,28 +297,38 @@
265297
/** ---------------------------------- Tests limits - to recalculate -------------------------------------------- */
266298

267299
// Gathered on this machine
268-
$loopMaxPhpTimesMHz = 3700;
300+
$loopMaxPhpTimesMHz = 3000;
269301
// How much time needed for tests on this machine
270302
$loopMaxPhpTimes = array(
271-
'4.4' => 235,
272-
'5.2' => 150,
273-
'5.3' => 130,
303+
'4.4' => 350,
304+
'5.2' => 237,
305+
'5.3' => 211,
274306
// 5.4, 5.5, 5.6
275-
'5' => 130,
307+
'5.4' => 191,
308+
'5.5' => 189,
309+
'5.6' => 190,
276310
// 7.0, 7.1
277-
'7' => 65,
311+
'7.0' => 109,
312+
'7.1' => 107,
313+
'7.2' => 105,
314+
'7.3' => 92,
278315
);
279316
$dumbTestMaxPhpTimes = array(
280-
'4.4' => 1.3,
281-
'5.2' => 0.97,
282-
'5.3' => 0.95,
317+
'4.4' => 2.13,
318+
'5.2' => 1.82,
319+
'5.3' => 1.82,
283320
// 5.4, 5.5, 5.6
284-
'5' => 0.95,
321+
'5.4' => 1.71,
322+
'5.5' => 1.86,
323+
'5.6' => 1.92,
285324
// 7.0, 7.1
286-
'7' => 0.58,
325+
'7.0' => 1.19,
326+
'7.1' => 1.19,
327+
'7.2' => 1.18,
328+
'7.3' => 1.05,
287329
);
288330
$testsLoopLimits = array(
289-
'01_math' => 1400000,
331+
'01_math' => 1000000,
290332
// Nice dice roll
291333
// That limit gives around 256Mb too
292334
'02_string_concat' => 7700000,
@@ -304,23 +346,47 @@
304346
'12_unserialize' => 1300000,
305347
'13_array_loop' => 200,
306348
'14_array_loop' => 200,
307-
'15_loops' => 190000000,
308-
'16_loop_ifelse' => 90000000,
309-
'17_loop_ternary' => 90000000,
349+
'15_loops' => 100000000,
350+
'16_loop_ifelse' => 50000000,
351+
'17_loop_ternary' => 50000000,
310352
'18_1_loop_def' => 20000000,
311353
'18_2_loop_undef' => 20000000,
312-
'19_type_func' => 5000000,
313-
'20_type_conv' => 5000000,
354+
'19_type_func' => 3000000,
355+
'20_type_conv' => 3000000,
314356
'21_loop_except' => 4000000,
315357
'22_loop_nullop' => 50000000,
316358
'23_loop_spaceship' => 50000000,
317359
'24_xmlrpc_encode' => 200000,
318360
'25_xmlrpc_decode' => 30000,
361+
'26_1_public' => 5000000,
362+
'26_2_getset' => 5000000,
363+
'26_3_magic' => 5000000,
319364
);
320365
$totalOps = 0;
321366

322367
/** ---------------------------------- Common functions -------------------------------------------- */
323368

369+
/**
370+
* Gt pretty OS release name, if available
371+
*/
372+
function get_current_os()
373+
{
374+
$osFile = '/etc/os-release';
375+
$result = PHP_OS;
376+
if (file_exists($osFile)) {
377+
$f = fopen($osFile, 'r');
378+
while (!feof($f)) {
379+
$line = trim(fgets($f, 1000000));
380+
if (strpos($line, 'PRETTY_NAME=') === 0) {
381+
$s = explode('=', $line);
382+
$result = array_pop($s);
383+
$result = str_replace('"','', $result);
384+
}
385+
}
386+
}
387+
return $result;
388+
}
389+
324390
function get_microtime()
325391
{
326392
$time = microtime(true);
@@ -658,7 +724,9 @@ function mymemory_usage()
658724
// TIME WASTED HERE
659725
$dumbTestTime = dumb_test_Functions();
660726
// Debug
661-
// print($dumbTestTime);
727+
if ($printDumbTest) {
728+
print("Dumb test time: " .$dumbTestTime . PHP_EOL);
729+
}
662730
if ($dumbTestTime > $dumbTestTimeMax) {
663731
$factor *= 1.0 * $dumbTestTimeMax / $dumbTestTime;
664732
}
@@ -1394,6 +1462,7 @@ function test_25_XmlRpc_Decode()
13941462
. str_pad("Start", $padInfo) . " : " . date("Y-m-d H:i:s") . "\n"
13951463
. str_pad("Server", $padInfo) . " : " . php_uname('s') . '/' . php_uname('r') . ' ' . php_uname('m') . "\n"
13961464
. str_pad("Platform", $padInfo) . " : " . PHP_OS . "\n"
1465+
. str_pad("System", $padInfo) . " : " . get_current_os() . "\n"
13971466
. str_pad("CPU", $padInfo) . " :\n"
13981467
. str_pad("model", $padInfo, ' ', STR_PAD_LEFT) . " : " . $cpuInfo['model'] . "\n"
13991468
. str_pad("cores", $padInfo, ' ', STR_PAD_LEFT) . " : " . $cpuInfo['cores'] . "\n"

php5.inc

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,71 @@
11
<?php
22

33
/**
4-
* Special test only for php 5+.
4+
* Special test only for php 5+
55
* php 4.x can't compile try construction.
66
*/
7+
8+
/* ------------------------ Additional data ------------------------ */
9+
10+
class PublicProperties
11+
{
12+
public $number = 0;
13+
}
14+
15+
class GetterSetter
16+
{
17+
private $number = 0;
18+
19+
public function getNumber()
20+
{
21+
return $this->number;
22+
}
23+
24+
public function setNumber($new)
25+
{
26+
$this->number = $new;
27+
return $this;
28+
}
29+
}
30+
31+
class MagicMethods
32+
{
33+
private $number = 0;
34+
35+
public function __get($name)
36+
{
37+
if ($name === 'number') {
38+
return $this->number;
39+
}
40+
return null;
41+
}
42+
43+
public function __set($name, $new)
44+
{
45+
if ($name === 'number') {
46+
$this->number = $new;
47+
}
48+
}
49+
}
50+
51+
/* ------------------------ Tests ------------------------ */
52+
753
function test_21_0_Loop_Exception_None()
854
{
9-
global $testsLoopLimits;
55+
global $testsLoopLimits, $totalOps;
1056

1157
$count = $testsLoopLimits['21_loop_except'];
1258
$time_start = get_microtime();
1359
for ($i = 0; $i < $count; $i++) {
1460
$a = $i;
1561
}
62+
$totalOps += $count;
1663
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
1764
}
1865

1966
function test_21_1_Loop_Exception_Try()
2067
{
21-
global $testsLoopLimits;
68+
global $testsLoopLimits, $totalOps;
2269

2370
$count = $testsLoopLimits['21_loop_except'];
2471
$time_start = get_microtime();
@@ -28,12 +75,13 @@ function test_21_1_Loop_Exception_Try()
2875
} catch (Exception $e) {
2976
}
3077
}
78+
$totalOps += $count;
3179
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
3280
}
3381

3482
function test_21_2_Loop_Exception_Catch()
3583
{
36-
global $testsLoopLimits;
84+
global $testsLoopLimits, $totalOps;
3785

3886
$count = $testsLoopLimits['21_loop_except'];
3987
$time_start = get_microtime();
@@ -44,5 +92,58 @@ function test_21_2_Loop_Exception_Catch()
4492
} catch (Exception $e) {
4593
}
4694
}
95+
$totalOps += $count;
96+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
97+
}
98+
99+
function test_26_1_Class_Public_Properties()
100+
{
101+
global $testsLoopLimits, $totalOps;
102+
103+
$c = new PublicProperties();
104+
$r = 0;
105+
106+
$count = $testsLoopLimits['26_1_public'];
107+
$time_start = get_microtime();
108+
for ($i = 0; $i < $count; $i++) {
109+
$r = $c->number;
110+
$c->number = $r + $i;
111+
}
112+
$totalOps += $count;
47113
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
48114
}
115+
116+
function test_26_2_Class_Getter_Setter()
117+
{
118+
global $testsLoopLimits, $totalOps;
119+
120+
$c = new GetterSetter();
121+
$r = 0;
122+
123+
$count = $testsLoopLimits['26_2_getset'];
124+
$time_start = get_microtime();
125+
for ($i = 0; $i < $count; $i++) {
126+
$r = $c->getNumber();
127+
$c->setNumber($r + $i);
128+
}
129+
$totalOps += $count;
130+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
131+
}
132+
133+
function test_26_3_Class_Magic_Methods()
134+
{
135+
global $testsLoopLimits, $totalOps;
136+
137+
$c = new MagicMethods();
138+
$r = 0;
139+
140+
$count = $testsLoopLimits['26_3_magic'];
141+
$time_start = get_microtime();
142+
for ($i = 0; $i < $count; $i++) {
143+
$r = $c->number;
144+
$c->number = $r + $i;
145+
}
146+
$totalOps += $count;
147+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
148+
}
149+

0 commit comments

Comments
 (0)