Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9ce3fc7

Browse files
Merge pull request 'For issue#22: raw numbers in output' (#24) from issue-22-raw-output into master
Reviewed-on: https://gitea.rusoft.ru/open-source/php-simple-benchmark-script/pulls/24
2 parents f1c46b3 + 1c7f22a commit 9ce3fc7

File tree

1 file changed

+55
-13
lines changed

1 file changed

+55
-13
lines changed

‎bench.php

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
# Company : Code24 BV, The Netherlands #
1010
# Author : Sergey Dryabzhinsky #
1111
# Company : Rusoft Ltd, Russia #
12-
# Date : Jun 7, 2025 #
13-
# Version : 1.0.66 #
12+
# Date : Jun 13, 2025 #
13+
# Version : 1.0.67-dev #
1414
# License : Creative Commons CC-BY license #
1515
# Website : https://github.com/rusoft/php-simple-benchmark-script #
1616
# Website : https://gitea.rusoft.ru/open-source/php-simple-benchmark-script #
@@ -20,7 +20,7 @@
2020

2121
include_once("php-options.php");
2222

23-
$scriptVersion = '1.0.66';
23+
$scriptVersion = '1.0.67-dev';
2424

2525
// Special string to flush buffers, nginx for example
2626
$flushStr = '<!-- '.str_repeat("", 8192).' -->';
@@ -197,6 +197,8 @@
197197

198198
$printJson = 0;
199199

200+
$printRaw = 0;
201+
200202
$printMachine = 0;
201203

202204
$recalculateLimits = 1;
@@ -237,9 +239,15 @@
237239
if ($x = (int)getenv('PRINT_JSON')) {
238240
$printJson = $x;
239241
}
242+
if ($x = (int)getenv('PRINT_RAW')) {
243+
$printRaw = $x;
244+
}
240245
if (isset($_GET['print_json']) && $x = (int)$_GET['print_json']) {
241246
$printJson = $x;
242247
}
248+
if (isset($_GET['print_raw']) && $x = (int)$_GET['print_raw']) {
249+
$printRaw = $x;
250+
}
243251
if ($printJson) $printMachine = 0;
244252

245253
if ($x = (int)getenv('PRINT_MACHINE')) {
@@ -368,6 +376,7 @@ function gethostname() {
368376
$shortopts .= "d";
369377
$shortopts .= "C";
370378
$shortopts .= "J";
379+
$shortopts .= "R";
371380
$shortopts .= "M";
372381
$shortopts .= "D";
373382
$shortopts .= "L";
@@ -382,6 +391,7 @@ function gethostname() {
382391
"debug",
383392
"dont-use-colors",
384393
"print-json",
394+
"print-raw",
385395
"print-machine",
386396
"dont-recalc",
387397
"dumb-test-print",
@@ -430,6 +440,11 @@ function gethostname() {
430440
$printMachine = 0;
431441
break;
432442

443+
case 'R':
444+
case 'print-raw':
445+
$printRaw = 1;
446+
break;
447+
433448
case 'M':
434449
case 'print-machine':
435450
$printMachine = 1;
@@ -480,12 +495,13 @@ function gethostname() {
480495
PHP_EOL
481496
. 'PHP Benchmark Performance Script, version ' . $scriptVersion . PHP_EOL
482497
. PHP_EOL
483-
. 'Usage: ' . basename(__FILE__) . ' [-h|--help] [-x|--debug] [-C|--dont-use-colors] [-J|--print-json] [-M|--print-machine] [-d|--dont-recalc] [-D|--dumb-test-print] [-L|--list-tests] [-I|--system-info] [-S|--do-not-task-set] [-m|--memory-limit=130] [-t|--time-limit=600] [-T|--run-test=name] [-S|--skip-test=pattern]' . PHP_EOL
498+
. 'Usage: ' . basename(__FILE__) . ' [-h|--help] [-x|--debug] [-C|--dont-use-colors] [-J|--print-json] [-R|--print-raw] [-M|--print-machine] [-d|--dont-recalc] [-D|--dumb-test-print] [-L|--list-tests] [-I|--system-info] [-S|--do-not-task-set] [-m|--memory-limit=130] [-t|--time-limit=600] [-T|--run-test=name] [-S|--skip-test=pattern]' . PHP_EOL
484499
. PHP_EOL
485500
. ' -h|--help - print this help and exit' . PHP_EOL
486501
. ' -x|--debug - enable debug mode, raise output level' . PHP_EOL
487-
. ' -C|--dont-use-colors - disable printing html-span or color sequences for capable terminal: xterm, *-color, *-256color. And not use it in JSON/machine mode.' . PHP_EOL
502+
. ' -C|--dont-use-colors - disable printing html-span or color sequences for capable terminal: xterm, *-color, *-256color. And not using it in JSON/machine mode.' . PHP_EOL
488503
. ' -J|--print-json - enable printing only in JSON format, useful for automated tests. disables print-machine.' . PHP_EOL
504+
. ' -R|--print-raw - enable printing only raw values, no human readable forms, useful for automated tests.' . PHP_EOL
489505
. ' -M|--print-machine - enable printing only in machine parsable format, useful for automated tests. disables print-json.' . PHP_EOL
490506
. ' -d|--dont-recalc - do not recalculate test times / operations count even if memory of execution time limits are low' . PHP_EOL
491507
. ' -D|--dumb-test-print - print dumb test time, for debug purpose' . PHP_EOL
@@ -504,12 +520,13 @@ function gethostname() {
504520
PHP_EOL
505521
. 'PHP Benchmark Performance Script, version ' . $scriptVersion . PHP_EOL
506522
. PHP_EOL
507-
. 'Usage: ' . basename(__FILE__) . ' [-h] [-x] [-C] [-J] [-M] [-d] [-D] [-L] [-I] [-S] [-m 130] [-t 600] [-T name]' . PHP_EOL
523+
. 'Usage: ' . basename(__FILE__) . ' [-h] [-x] [-C] [-J] [-R] [-M] [-d] [-D] [-L] [-I] [-S] [-m 130] [-t 600] [-T name]' . PHP_EOL
508524
. PHP_EOL
509525
. ' -h - print this help and exit' . PHP_EOL
510526
. ' -x - enable debug mode, raise output level' . PHP_EOL
511-
. ' -C - disable printing html-span or color sequences for capable terminal: xterm, *-color, *-256color. And not use it in JSON/machine mode.' . PHP_EOL
527+
. ' -C - disable printing html-span or color sequences for capable terminal: xterm, *-color, *-256color. And not using it in JSON/machine mode.' . PHP_EOL
512528
. ' -J - enable printing only in JSON format, useful for automated tests. disables print-machine.' . PHP_EOL
529+
. ' -R - enable printing only raw values, no human readable forms, useful for automated tests.' . PHP_EOL
513530
. ' -M - enable printing only in machine parsable format, useful for automated tests. disables print-json.' . PHP_EOL
514531
. ' -d - do not recalculate test times / operations count even if memory of execution time limits are low' . PHP_EOL
515532
. ' -D - print dumb test time, for debug purpose' . PHP_EOL
@@ -579,6 +596,8 @@ function gethostname() {
579596
case 'dont-use-colors':
580597
case 'J':
581598
case 'print-json':
599+
case 'R':
600+
case 'print-raw':
582601
case 'M':
583602
case 'print-machine':
584603
case 'D':
@@ -1562,8 +1581,13 @@ function mymemory_usage()
15621581
*/
15631582
function format_result_test($diffSeconds, $opCount, $memory = 0)
15641583
{
1565-
global $cpuInfo, $rawValues4json;
1584+
global $cpuInfo, $rawValues4json, $printRaw;
15661585
if ($diffSeconds) {
1586+
if ($printRaw) {
1587+
return array($diffSeconds, number_format($diffSeconds, 3, '.', ''),
1588+
$opCount, 0, $memory
1589+
);
1590+
}
15671591
$ops = $opCount / $diffSeconds;
15681592
$ops_v = convert_si($ops);
15691593
$ops_u = prefix_si($ops);
@@ -1589,6 +1613,9 @@ function format_result_test($diffSeconds, $opCount, $memory = 0)
15891613
if ($rawValues4json) {
15901614
return array(0, 0, 0, 0, 0);
15911615
}
1616+
if ($printRaw) {
1617+
return array(0, 0, 0, 0, 0);
1618+
}
15921619
return array(0, '0.000', 'x.xx ', 'x.xx ', 0);
15931620
}
15941621
}
@@ -1947,12 +1974,14 @@ function filter_out_name_by_pattern($key)
19471974
if (!defined('SODIUM_LIBRARY_VERSION')) define('SODIUM_LIBRARY_VERSION', '-.-.-');
19481975
if (!defined('INTL_ICU_VERSION')) define('INTL_ICU_VERSION', '-.-');
19491976
if (!defined('LIBZSTD_VERSION_STRING')) define('LIBZSTD_VERSION_STRING', '-.-.-');
1977+
if (!defined('BROTLI_VERSION_TEXT')) define('BROTLI_VERSION_TEXT', '-.-.-');
19501978

19511979
function print_results_common()
19521980
{
19531981
$total = 0;
19541982

19551983
global $availableFunctions;
1984+
global $printRaw;
19561985
global $line, $padHeader, $cpuInfo, $padInfo, $scriptVersion, $maxTime, $originTimeLimit, $originMemoryLimit, $cryptAlgoName, $memoryLimitMb;
19571986
global $flushStr, $has_apc, $has_pcre, $has_intl, $has_json, $has_simplexml, $has_dom, $has_mbstring, $has_opcache, $has_xcache;
19581987
global $has_gd, $has_gdgif, $has_gdpng, $has_gdjpg, $has_gdwebp, $has_gdavif;
@@ -2039,7 +2068,12 @@ function print_results_common()
20392068

20402069
if (!$showOnlySystemInfo) {
20412070

2042-
echo str_pad('TEST NAME', $padLabel) . " :"
2071+
if ($printRaw)
2072+
echo str_pad('TEST NAME', $padLabel) . " :"
2073+
. str_pad('SECONDS', 9 + 4, '', STR_PAD_LEFT) . " |" . str_pad('OPS', 9 + 4, '', STR_PAD_LEFT) . " |" . str_pad('OP/SEC/MHz', 9 + 7, '', STR_PAD_LEFT) . " |" . str_pad('MEMORY b', 10, '', STR_PAD_LEFT) . "\n"
2074+
. "$line\n" . $flushStr;
2075+
else
2076+
echo str_pad('TEST NAME', $padLabel) . " :"
20432077
. str_pad('SECONDS', 9 + 4, '', STR_PAD_LEFT) . " |" . str_pad('OP/SEC', 9 + 4, '', STR_PAD_LEFT) . " |" . str_pad('OP/SEC/MHz', 9 + 7, '', STR_PAD_LEFT) . " |" . str_pad('MEMORY', 10, '', STR_PAD_LEFT) . "\n"
20442078
. "$line\n" . $flushStr;
20452079
flush();
@@ -2055,7 +2089,10 @@ function print_results_common()
20552089
echo str_pad($testName, $padLabel) . " :";
20562090
list($resultSec, $resultSecFmt, $resultOps, $resultOpMhz, $memory) = $user();
20572091
$total += $resultSec;
2058-
echo str_pad($resultSecFmt, 9, '', STR_PAD_LEFT) . " sec |" . str_pad($resultOps, 9, '', STR_PAD_LEFT) . "Op/s |" . str_pad($resultOpMhz, 9, '', STR_PAD_LEFT) . "Ops/MHz |" . str_pad($memory, 10, '', STR_PAD_LEFT) . "\n";
2092+
if ($printRaw)
2093+
echo str_pad($resultSecFmt, 9, '', STR_PAD_LEFT) . " |" . str_pad($resultOps, 9, '', STR_PAD_LEFT) . " |" . str_pad($resultOpMhz, 9, '', STR_PAD_LEFT) . " |" . str_pad($memory, 10, '', STR_PAD_LEFT) . "\n";
2094+
else
2095+
echo str_pad($resultSecFmt, 9, '', STR_PAD_LEFT) . " sec |" . str_pad($resultOps, 9, '', STR_PAD_LEFT) . "Op/s |" . str_pad($resultOpMhz, 9, '', STR_PAD_LEFT) . "Ops/MHz |" . str_pad($memory, 10, '', STR_PAD_LEFT) . "\n";
20592096
echo $flushStr;
20602097
flush();
20612098
}
@@ -2064,14 +2101,19 @@ function print_results_common()
20642101
list($resultSec, $resultSecFmt, $resultOps, $resultOpMhz, $memory) = format_result_test($total, $totalOps, 0);
20652102

20662103
echo "$line\n"
2067-
. str_pad("Total:", $padLabel) . " :";
2068-
echo str_pad($resultSecFmt, 9, '', STR_PAD_LEFT) . " sec |" . str_pad($resultOps, 9, '', STR_PAD_LEFT) . "Op/s |" . str_pad($resultOpMhz, 9, '', STR_PAD_LEFT) . "Ops/MHz |" . "\n";
2069-
echo str_pad("Current PHP memory usage:", $padLabel) . " :" . str_pad(convert(mymemory_usage()), 12, '', STR_PAD_LEFT) . "\n"
2104+
. str_pad("Total:", $padLabel) . " :";
2105+
if ($printRaw) {
2106+
echo str_pad($resultSecFmt, 9, '', STR_PAD_LEFT) . " |" . str_pad($resultOps, 9, '', STR_PAD_LEFT) . " |" . str_pad($resultOpMhz, 9, '', STR_PAD_LEFT) . " |" . "\n";
2107+
echo str_pad("Current PHP memory usage:", $padLabel) . " :" . str_pad(mymemory_usage(), 12, '', STR_PAD_LEFT) . "\n";
2108+
} else {
2109+
echo str_pad($resultSecFmt, 9, '', STR_PAD_LEFT) . " sec |" . str_pad($resultOps, 9, '', STR_PAD_LEFT) . "Op/s |" . str_pad($resultOpMhz, 9, '', STR_PAD_LEFT) . "Ops/MHz |" . "\n";
2110+
echo str_pad("Current PHP memory usage:", $padLabel) . " :" . str_pad(convert(mymemory_usage()), 12, '', STR_PAD_LEFT) . "\n"
20702111
// php-4 don't have peak_usage function
20712112
. (function_exists('memory_get_peak_usage')
20722113
? str_pad("Peak PHP memory usage:", $padLabel) . " :" . str_pad(convert(memory_get_peak_usage()), 12, '', STR_PAD_LEFT) . "\n"
20732114
: ''
20742115
);
2116+
}
20752117

20762118
echo "$line\n";
20772119
echo str_pad("End", $padLabel) . " : " . date("Y-m-d H:i:s") . "\n";

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /