Skip to content

Commit dc38e44

Browse files
Version 1.0.15
* Поправили работу скрипта с php-7.x - больше ограничений по памяти * Добавили вывод используемой памяти (@ryr)
1 parent d920b01 commit dc38e44

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
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+
@ 2017-05-17, v1.0.15
8+
9+
* Поправили работу скрипта с php-7.x - больше ограничений по памяти
10+
* Добавили вывод используемой памяти (@ryr)
11+
712
@ 2017-05-06, v1.0.14
813

914
* Изменили работу скрипта, если доступно памяти менее 256Мб

bench.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,41 @@
1010
# Author : Sergey Dryabzhinsky #
1111
# Company : Rusoft Ltd, Russia #
1212
# Date : May 15, 2017 #
13-
# version : 1.0.14 #
13+
# version : 1.0.15 #
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.14';
21+
$scriptVersion = '1.0.15';
22+
23+
// Used in hacks/fixes checks
24+
$phpversion = explode('.', PHP_VERSION);
2225

2326
$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валар дохаэрис ";
2427
$regexPattern = '/[\s,]+/';
2528

26-
set_time_limit(0);
29+
set_time_limit(600);
2730
@ini_set('memory_limit', '256M');
2831

2932
$line = str_pad("-", 91, "-");
3033
$padHeader = 89;
3134
$padInfo = 18;
3235
$padLabel = 31;
3336

34-
$emptyResult = array(0, '-.---', '-.--', '-.--');
37+
$emptyResult = array(0, '-.---', '-.--', '-.--', 0);
3538

3639
// That gives around 256Mb memory use and reasonable test time
40+
$testMemoryFull = 256*1024*1024;
3741
// Arrays are matrix [$dimention] x [$dimention]
38-
$arrayTestMemoryMinimum = 256*1024*1024;
3942
$arrayTestLoopLimit = 300;
4043
$arrayDimensionLimit = 300;
4144
// That limit gives around 256Mb too
4245
$stringConcatLoopRepeat = 1;
43-
$stringConcatLoopLimit = 7760000;
46+
// Nice dice roll
47+
$stringConcatLoopLimit = 7700000;
4448

4549
function get_microtime()
4650
{
@@ -233,22 +237,28 @@ function getCpuInfo($fireUpCpu = false)
233237
}
234238

235239
$memoryLimit = min(getPhpMemoryLimitBytes(), getSystemMemoryFreeLimitBytes());
236-
$memoryLimitMb = number_format($memoryLimit/1024.0/1024.0, 1, '.', '');
240+
$memoryLimitMb = convert($memoryLimit);
237241

238242
// Adjust array tests limits
239-
if ($memoryLimit < $arrayTestMemoryMinimum) {
243+
if ($memoryLimit < $testMemoryFull) {
240244

241245
print("<pre>\n<<< WARNING >>>\nAvailable memory for tests: ".$memoryLimitMb
242-
." MB is less than minimum required: ".number_format($arrayTestMemoryMinimum/1024.0/1024.0, 1, '.', '')
243-
." MB.\n Recalculate tests parameters to fit in memory limits."
246+
." is less than minimum required: ".convert($testMemoryFull)
247+
.".\n Recalculate tests parameters to fit in memory limits."
244248
."\n</pre>" . PHP_EOL);
245249

246-
$factor = 1.0 * ($arrayTestMemoryMinimum - $memoryLimit) / $arrayTestMemoryMinimum;
250+
$factor = 1.0 * ($testMemoryFull - $memoryLimit) / $testMemoryFull;
247251
$diff = (int)($factor * $arrayDimensionLimit);
248252
$arrayTestLoopLimit += (int)(1.0 * pow($arrayDimensionLimit, 2) * $arrayTestLoopLimit / pow($arrayDimensionLimit - $diff, 2));
249253
$arrayDimensionLimit -= $diff;
250254

251255
$diff = (int)($factor * $stringConcatLoopLimit);
256+
257+
// Special hack for php-7.x
258+
// New string classes, new memory allocator
259+
// Consumes more, allocate huge blocks
260+
if ((int)$phpversion[0] >= 7) $diff = (int)($diff * 1.1);
261+
252262
$stringConcatLoopRepeat = (int)(1.0 * ($stringConcatLoopLimit * $stringConcatLoopRepeat) / ($stringConcatLoopLimit - $diff));
253263
$stringConcatLoopLimit -= $diff;
254264
}
@@ -631,8 +641,7 @@ function test_17_2_Loop_Undefined_Access($count = 20000000)
631641
return format_result_test(get_microtime() - $time_start, $count, memory_get_usage(true));
632642
}
633643

634-
$version = explode('.', PHP_VERSION);
635-
if ((int)$version[0] >= 5) {
644+
if ((int)$phpversion[0] >= 5) {
636645
include_once 'php5.inc';
637646
}
638647

@@ -649,7 +658,7 @@ function test_17_2_Loop_Undefined_Access($count = 20000000)
649658
. str_pad("model", $padInfo, ' ', STR_PAD_LEFT) . " : " . $cpuInfo['model'] . "\n"
650659
. str_pad("cores", $padInfo, ' ', STR_PAD_LEFT) . " : " . $cpuInfo['cores'] . "\n"
651660
. str_pad("MHz", $padInfo, ' ', STR_PAD_LEFT) . " : " . $cpuInfo['mhz'] . 'MHz' . "\n"
652-
. str_pad("Memory", $padInfo) . " : " . $memoryLimitMb . 'MB available' . "\n"
661+
. str_pad("Memory", $padInfo) . " : " . $memoryLimitMb . ' available' . "\n"
653662
. str_pad("PHP version:", $padInfo) . " : " . PHP_VERSION . "\n"
654663
. str_pad("Benchmark version:", $padInfo) . " : " . $scriptVersion . "\n"
655664
. str_pad("Platform:", $padInfo) . " : " . PHP_OS . "\n"

0 commit comments

Comments
 (0)