Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ env PHP_MEMORY_LIMIT=64 PHP_TIME_LIMIT=30 php bench.php

## ChangeLog

@ 2019-05-10, v1.0.34

* Поправлено определение модели CPU и частота в MHz для процессоров ARM.

@ 2019-05-01, v1.0.33

* Новый тест для классов - доступ в данным через публичные свойства,
Expand Down
87 changes: 79 additions & 8 deletions bench.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
# Company : Code24 BV, The Netherlands #
# Author : Sergey Dryabzhinsky #
# Company : Rusoft Ltd, Russia #
# Date : MAy 01, 2019 #
# Version : 1.0.33 #
# Date : May 10, 2019 #
# Version : 1.0.34 #
# 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 #
# #
################################################################################
*/

$scriptVersion = '1.0.33';
$scriptVersion = '1.0.34';

ini_set('display_errors', 0);
ini_set('error_log', null);
Expand Down Expand Up @@ -272,6 +272,10 @@
// Special for nginx
header('X-Accel-Buffering: no');

if (file_exists('/usr/bin/taskset')) {
shell_exec('/usr/bin/taskset -c -p 0 ' . getmypid());
}

/** ------------------------------- Main Constants ------------------------------- */

$line = str_pad("-", 91, "-");
Expand Down Expand Up @@ -502,13 +506,17 @@ function getCpuInfo($fireUpCpu = false)
{
$cpu = array(
'model' => '',
'vendor' => '',
'cores' => 0,
'mhz' => 0.0,
'max-mhz' => 0.0,
'min-mhz' => 0.0,
'mips' => 0.0
);

if (!is_readable('/proc/cpuinfo')) {
$cpu['model'] = 'Unknown';
$cpu['vendor'] = 'Unknown';
$cpu['cores'] = 1;
return $cpu;
}
Expand All @@ -518,6 +526,9 @@ function getCpuInfo($fireUpCpu = false)
$i = 30000000;
while ($i--) ;
}
if (file_exists('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq')) {
$cpu['mhz'] = ((int)file_get_contents('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq'))/1000.0;
}

// Code from https://github.com/jrgp/linfo/blob/master/src/Linfo/OS/Linux.php
// Adopted
Expand Down Expand Up @@ -553,7 +564,8 @@ function getCpuInfo($fireUpCpu = false)
$cpu['mhz'] = (int)hexdec($value) / 1000000.0;
}
break;
case 'bogomips': // twice of MHz usualy
case 'bogomips': // twice of MHz usualy on Intel/Amd
case 'BogoMIPS': // twice of MHz usualy on Intel/Amd
if (empty($cpu['mhz'])) {
$cpu['mhz'] = (float)$value / 2.0;
}
Expand All @@ -570,6 +582,57 @@ function getCpuInfo($fireUpCpu = false)
}
}

// Raspberry Pi or other ARM board etc.
$cpuData = explode("\n", shell_exec('lscpu'));
foreach ($cpuData as $line) {
$line = explode(':', $line, 2);

if (!array_key_exists(1, $line)) {
continue;
}

$key = trim($line[0]);
$value = trim($line[1]);

// What we want are bogomips, MHz, processor, and Model.
switch ($key) {
// CPU model
case 'Model name':
if (empty($cpu['model'])) {
$cpu['model'] = $value;
}
break;
// cores
case 'CPU(s)':
if (empty($cpu['cores'])) {
$cpu['cores'] = (int)$value;
}
break;
// MHz
case 'CPU max MHz':
if (empty($cpu['max-mhz'])) {
$cpu['max-mhz'] = (int)$value;
}
break;
case 'CPU min MHz':
if (empty($cpu['min-mhz'])) {
$cpu['min-mhz'] = (int)$value;
}
break;
// vendor
case 'Vendor ID':
if (empty($cpu['vendor'])) {
$cpu['vendor'] = $value;
}
break;
}
}

if ($cpu['vendor'] == 'ARM') {
// Unusable
$cpu['mips'] = 0;
}

return $cpu;
}

Expand Down Expand Up @@ -654,10 +717,18 @@ function mymemory_usage()

$cpuInfo = getCpuInfo();
// CPU throttling?
if (abs($cpuInfo['mips'] - $cpuInfo['mhz']) > 300) {
print("<pre>\n<<< WARNING >>>\nCPU is in powersaving mode? Set CPU governor to 'performance'!\n Fire up CPU and recalculate MHz!\n</pre>" . PHP_EOL);
// TIME WASTED HERE
$cpuInfo = getCpuInfo(true);
if ($cpuInfo['mips'] && $cpuInfo['mhz']) {
if (abs($cpuInfo['mips'] - $cpuInfo['mhz']) > 300) {
print("<pre>\n<<< WARNING >>>\nCPU is in powersaving mode? Set CPU governor to 'performance'!\n Fire up CPU and recalculate MHz!\n</pre>" . PHP_EOL);
// TIME WASTED HERE
$cpuInfo = getCpuInfo(true);
}
} else if ($cpuInfo['max-mhz'] && $cpuInfo['mhz']) {
if (abs($cpuInfo['max-mhz'] - $cpuInfo['mhz']) > 300) {
print("<pre>\n<<< WARNING >>>\nCPU is in powersaving mode? Set CPU governor to 'performance'!\n Fire up CPU and recalculate MHz!\n</pre>" . PHP_EOL);
// TIME WASTED HERE
$cpuInfo = getCpuInfo(true);
}
}

$memoryLimit = min(getPhpMemoryLimitBytes(), getSystemMemoryFreeLimitBytes());
Expand Down