Skip to content

Commit 11e4249

Browse files
First variant of the test, need to test speed, adjust values
1 parent 48ba1f6 commit 11e4249

File tree

3 files changed

+139
-9
lines changed

3 files changed

+139
-9
lines changed

bench.php

+30-3
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@
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';
2222

2323
// Used in hacks/fixes checks
2424
$phpversion = explode('.', PHP_VERSION);
2525

2626
$dropDead = false;
27+
// No php < 4
2728
if ((int)$phpversion[0] < 4) {
2829
$dropDead = true;
2930
}
31+
// No php <= 4.3
3032
if ((int)$phpversion[0] == 4 && (int)$phpversion[1] < 3) {
3133
$dropDead = true;
3234
}
@@ -316,11 +318,35 @@
316318
'23_loop_spaceship' => 50000000,
317319
'24_xmlrpc_encode' => 200000,
318320
'25_xmlrpc_decode' => 30000,
321+
'26_1_public' => 10000000,
322+
'26_2_getset' => 10000000,
323+
'26_3_magic' => 10000000,
319324
);
320325
$totalOps = 0;
321326

322327
/** ---------------------------------- Common functions -------------------------------------------- */
323328

329+
/**
330+
* Gt pretty OS release name, if available
331+
*/
332+
function get_current_os()
333+
{
334+
$osFile = '/etc/os-release';
335+
$result = PHP_OS;
336+
if (is_file($osFile)) {
337+
$f = fopen($osFile, 'r');
338+
while (!feof($f)) {
339+
$line = stream_get_line($f, 1000000, "\n");
340+
if (strpos($line, 'PRETTY_NAME=') === 0) {
341+
$s = explode('=', $line);
342+
$result = array_pop($s);
343+
$result = str_replace('"','', $result);
344+
}
345+
}
346+
}
347+
return $result;
348+
}
349+
324350
function get_microtime()
325351
{
326352
$time = microtime(true);
@@ -1394,6 +1420,7 @@ function test_25_XmlRpc_Decode()
13941420
. str_pad("Start", $padInfo) . " : " . date("Y-m-d H:i:s") . "\n"
13951421
. str_pad("Server", $padInfo) . " : " . php_uname('s') . '/' . php_uname('r') . ' ' . php_uname('m') . "\n"
13961422
. str_pad("Platform", $padInfo) . " : " . PHP_OS . "\n"
1423+
. str_pad("System", $padInfo) . " : " . get_current_os() . "\n"
13971424
. str_pad("CPU", $padInfo) . " :\n"
13981425
. str_pad("model", $padInfo, ' ', STR_PAD_LEFT) . " : " . $cpuInfo['model'] . "\n"
13991426
. str_pad("cores", $padInfo, ' ', STR_PAD_LEFT) . " : " . $cpuInfo['cores'] . "\n"

php5.inc

+105-4
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_1_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_2_Class_Magic_Methods()
134+
{
135+
global $testsLoopLimits, $totalOps;
136+
137+
$c = new MagicMethods();
138+
$r = 0;
139+
140+
$count = $testsLoopLimits['26_1_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+

php7.inc

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
function test_22_Loop_Null_Op()
77
{
8-
global $testsLoopLimits;
8+
global $testsLoopLimits, $totalOps;
99

1010
$a = array(0 => 0, 2 => 2, 4 => 4);
1111

@@ -14,17 +14,19 @@ function test_22_Loop_Null_Op()
1414
for ($i = 0; $i < $count; $i++) {
1515
$r = $a[$i % 2] ?? 0;
1616
}
17+
$totalOps += $count;
1718
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
1819
}
1920

2021
function test_23_Loop_Spaceship_Op()
2122
{
22-
global $testsLoopLimits;
23+
global $testsLoopLimits, $totalOps;
2324

2425
$count = $testsLoopLimits['23_loop_spaceship'];
2526
$time_start = get_microtime();
2627
for ($i = 0; $i < $count; $i++) {
2728
$r = $i % 5 <=> 2;
2829
}
30+
$totalOps += $count;
2931
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
3032
}

0 commit comments

Comments
 (0)