Skip to content

Commit 99b7b6d

Browse files
Обновил тесты
1 parent 444283b commit 99b7b6d

File tree

2 files changed

+168
-11
lines changed

2 files changed

+168
-11
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
## ChangeLog
66

7+
@ 2015-07-01
8+
9+
* Добавлено еще больше функций, теперь трубается наличие mbstring и json модулей
10+
* Потребление памяти увеличено из-за тестирования массивов - нужно более 1Гб
11+
712
@ 2015-07-01
813

914
* Добавлен вывод потребления памяти

bench.php

Lines changed: 163 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
# Company : Code24 BV, The Netherlands #
1111
# Company : Rusoft Ltd, Russia #
1212
# Date : July 1, 2015 #
13-
# version : 1.01 #
13+
# version : 1.0.2 #
1414
# License : Creative Commons CC-BY license #
1515
# Website : http://www.php-benchmark-script.com #
1616
# #
1717
##########################################################################
1818
*/
1919

20+
$scriptVersion = '1.0.2';
21+
22+
$stringTest = " the quick <b>brown</b> fox jumps <i>over</i> the lazy dog and eat <span>lorem ipsum valar morgulis \n\rабыр\nвалар дохаэрис ";
23+
24+
// Need alot of memory - more 1Gb
25+
$doTestArrays = false;
26+
2027
function get_microtime()
2128
{
2229
$time = microtime(true);
@@ -33,7 +40,6 @@ function convert($size)
3340
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
3441
}
3542

36-
3743
function test_Math($count = 1400000) {
3844
$time_start = get_microtime();
3945
$mathFunctions = array("abs", "acos", "asin", "atan", "decbin", "dechex", "decoct", "floor", "exp", "log1p", "sin", "tan", "pi", "is_finite", "is_nan", "sqrt", "rad2deg");
@@ -48,21 +54,149 @@ function test_Math($count = 1400000) {
4854
return number_format(get_microtime() - $time_start, 3);
4955
}
5056

51-
function test_StringManipulation($count = 1300000) {
57+
function test_String_Simple($count = 1300000) {
58+
global $stringTest;
59+
$time_start = get_microtime();
60+
$stringFunctions = array("strtoupper", "strtolower", "strrev", "strlen", "str_rot13", "ord", "trim");
61+
foreach ($stringFunctions as $key => $function) {
62+
if (!function_exists($function)) unset($stringFunctions[$key]);
63+
}
64+
for ($i=0; $i < $count; $i++) {
65+
foreach ($stringFunctions as $function) {
66+
$r = call_user_func_array($function, array($stringTest));
67+
}
68+
}
69+
return number_format(get_microtime() - $time_start, 3);
70+
}
71+
72+
function test_String_Multibyte($count = 130000) {
73+
global $stringTest;
5274
$time_start = get_microtime();
53-
$stringFunctions = array("addslashes", "chunk_split", "metaphone", "strip_tags", "crc32", "md5", "sha1", "strtoupper", "strtolower", "strrev", "strlen", "str_rot13", "soundex", "ord", "wordwrap");
75+
$stringFunctions = array("mb_strtoupper", "mb_strtolower", "mb_strlen", "mb_strwidth");
5476
foreach ($stringFunctions as $key => $function) {
5577
if (!function_exists($function)) unset($stringFunctions[$key]);
5678
}
57-
$string = "the quick <b>brown</b> fox jumps <i>over</i> the lazy dog and eat <span>lorem ipsum volar morgulis";
5879
for ($i=0; $i < $count; $i++) {
5980
foreach ($stringFunctions as $function) {
60-
$r = call_user_func_array($function, array($string));
81+
$r = call_user_func_array($function, array($stringTest));
82+
}
83+
}
84+
return number_format(get_microtime() - $time_start, 3);
85+
}
86+
87+
function test_String_Manipulation($count = 1300000) {
88+
global $stringTest;
89+
$time_start = get_microtime();
90+
$stringFunctions = array("addslashes", "chunk_split", "metaphone", "strip_tags", "soundex", "wordwrap");
91+
foreach ($stringFunctions as $key => $function) {
92+
if (!function_exists($function)) unset($stringFunctions[$key]);
93+
}
94+
for ($i=0; $i < $count; $i++) {
95+
foreach ($stringFunctions as $function) {
96+
$r = call_user_func_array($function, array($stringTest));
97+
}
98+
}
99+
return number_format(get_microtime() - $time_start, 3);
100+
}
101+
102+
function test_Hashing($count = 1300000) {
103+
global $stringTest;
104+
$time_start = get_microtime();
105+
$stringFunctions = array("crc32", "md5", "sha1",);
106+
foreach ($stringFunctions as $key => $function) {
107+
if (!function_exists($function)) unset($stringFunctions[$key]);
108+
}
109+
for ($i=0; $i < $count; $i++) {
110+
foreach ($stringFunctions as $function) {
111+
$r = call_user_func_array($function, array($stringTest));
112+
}
113+
}
114+
return number_format(get_microtime() - $time_start, 3);
115+
}
116+
117+
function test_Json_Encode($count = 1300000) {
118+
global $stringTest;
119+
$time_start = get_microtime();
120+
$stringFunctions = array("json_encode",);
121+
foreach ($stringFunctions as $key => $function) {
122+
if (!function_exists($function)) unset($stringFunctions[$key]);
123+
}
124+
$data = array(
125+
$stringTest,
126+
123456,
127+
123.456,
128+
array(123456),
129+
null,
130+
false,
131+
);
132+
foreach ($stringFunctions as $function) {
133+
for ($i=0; $i < $count; $i++) {
134+
foreach ($data as $value) {
135+
$r = call_user_func_array($function, array($value));
136+
}
137+
}
138+
}
139+
return number_format(get_microtime() - $time_start, 3);
140+
}
141+
142+
function test_Json_Decode($count = 1300000) {
143+
global $stringTest;
144+
$time_start = get_microtime();
145+
$stringFunctions = array("json_decode",);
146+
foreach ($stringFunctions as $key => $function) {
147+
if (!function_exists($function)) unset($stringFunctions[$key]);
148+
}
149+
$data = array(
150+
$stringTest,
151+
123456,
152+
123.456,
153+
array(123456),
154+
null,
155+
false,
156+
);
157+
foreach ($data as $key => $value) {
158+
$data[ $key ] = json_encode($value);
159+
}
160+
foreach ($stringFunctions as $function) {
161+
for ($i=0; $i < $count; $i++) {
162+
foreach ($data as $value) {
163+
$r = call_user_func_array($function, array($value));
164+
}
61165
}
62166
}
63167
return number_format(get_microtime() - $time_start, 3);
64168
}
65169

170+
function test_Array_Fill($count = 3000) {
171+
global $doTestArrays;
172+
if (!$doTestArrays) return '-.---';
173+
174+
$time_start = get_microtime();
175+
for($i = 0; $i < $count; ++$i) {
176+
for($j = 0; $j < $count; ++$j) {
177+
$X[ $i ][ $j ] = $i * $j;
178+
}
179+
}
180+
return number_format(get_microtime() - $time_start, 3);
181+
}
182+
183+
function test_Array_Unset($count = 3000) {
184+
global $doTestArrays;
185+
if (!$doTestArrays) return '-.---';
186+
187+
$time_start = get_microtime();
188+
$X = range(0, $count);
189+
for($i = 0; $i < $count; ++$i) {
190+
$X[ $i ] = range(0, $count);
191+
}
192+
for($i = $count-1; $i >= 0; $i--) {
193+
for($j = 0; $j < $count; ++$j) {
194+
unset($X[ $i ][ $j ]);
195+
}
196+
unset($X[ $i ]);
197+
}
198+
return number_format(get_microtime() - $time_start, 3);
199+
}
66200

67201
function test_Loops($count = 190000000) {
68202
$time_start = get_microtime();
@@ -71,24 +205,42 @@ function test_Loops($count = 190000000) {
71205
return number_format(get_microtime() - $time_start, 3);
72206
}
73207

74-
75208
function test_IfElse($count = 90000000) {
76209
$time_start = get_microtime();
77210
for ($i=0; $i < $count; $i++) {
78211
if ($i == -1) {
79212
} elseif ($i == -2) {
80213
} else if ($i == -3) {
81214
} else {
82-
}
215+
}
83216
}
84217
return number_format(get_microtime() - $time_start, 3);
85218
}
86-
87-
219+
220+
function test_Ternary($count = 90000000) {
221+
$time_start = get_microtime();
222+
for ($i=0; $i < $count; $i++) {
223+
$r = ($i % 2 == 1)
224+
? ( ($i % 3 == 1)
225+
? ( ($i % 5 == 1)
226+
? 3
227+
: 2 )
228+
: 1 )
229+
: 0;
230+
}
231+
return number_format(get_microtime() - $time_start, 3);
232+
}
233+
88234
$total = 0;
89235
$functions = get_defined_functions();
90236
$line = str_pad("-",38,"-");
91-
echo "<pre>\n$line\n|".str_pad("PHP BENCHMARK SCRIPT",36," ",STR_PAD_BOTH)."|\n$line\nStart : ".date("Y-m-d H:i:s")."\nServer : ".php_uname()."\nPHP version : ".PHP_VERSION."\nPlatform : ".PHP_OS. "\n$line\n";
237+
echo "<pre>\n$line\n|".str_pad("PHP BENCHMARK SCRIPT",36," ",STR_PAD_BOTH)
238+
."|\n$line\nStart : ".date("Y-m-d H:i:s")
239+
."\nServer : ".php_uname()
240+
."\nPHP version : ".PHP_VERSION
241+
."\nBenchmark version : ".$scriptVersion
242+
."\nPlatform : ".PHP_OS
243+
. "\n$line\n";
92244
foreach ($functions['user'] as $user) {
93245
if (preg_match('/^test_/', $user)) {
94246
$result = $user();

0 commit comments

Comments
 (0)