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 a2da094

Browse files
Merge pull request 'issue-9-skipping-tests-by-pattern' (#13) from issue-9-skipping-tests-by-pattern into master
Reviewed-on: https://gitea.rusoft.ru/open-source/php-simple-benchmark-script/pulls/13
2 parents 5812e33 + b75db82 commit a2da094

File tree

4 files changed

+71
-42
lines changed

4 files changed

+71
-42
lines changed

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ChangeLog
22

3+
@ 2025年05月30日, v1.0.60
4+
5+
* Added ability to skip tests by name pattern
6+
37
@ 2025年05月29日, v1.0.59
48

59
* Added support of module uuid

‎README.en.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Usage: bench.php [-h|--help] [-x|--debug] [-C|--dont-use-colors] [-J|--print-jso
6262
-m|--memory-limit <Mb> - set memory_limit value in Mb, defaults to 130 (Mb)
6363
-t|--time-limit <sec> - set max_execution_time value in seconds, defaults to 600 (sec)
6464
-T|--run-test <name> - run selected test, test names from --list-tests output, can be defined multiple times
65+
-S|--skip-test <pattern> - skip selected test, test names pattern from --list-tests output, can be defined multiple times
6566
```
6667
Example: `php bench.php -m=64 -t=30`
6768

@@ -82,6 +83,7 @@ Available variables:
8283
- LIST_TESTS=0/1
8384
- SYSTEM_INFO=0/1
8485
- RUN_TESTS=test1,test2,...
86+
- SKIP_TESTS=test1,test2,...
8587

8688
#### Extras (Utilities in Linux)
8789

@@ -110,6 +112,7 @@ Available options:
110112
- list_tests=0/1
111113
- system_info=0/1
112114
- run_tests=test1,test2,...
115+
- skip_tests=test1,test2,...
113116

114117
### Accounting for hosting options
115118

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Usage: bench.php [-h|--help] [-x|--debug] [-C|--dont-use-colors] [-J|--print-jso
6262
-m|--memory-limit <Mb> - set memory_limit value in Mb, defaults to 130 (Mb)
6363
-t|--time-limit <sec> - set max_execution_time value in seconds, defaults to 600 (sec)
6464
-T|--run-test <name> - run selected test, test names from --list-tests output, can be defined multiple times
65+
-S|--skip-test <pattern> - skip selected test, test names pattern from --list-tests output, can be defined multiple times
6566
```
6667
Например: `php bench.php -m=64 -t=30`
6768

@@ -82,6 +83,7 @@ env PHP_MEMORY_LIMIT=64 PHP_TIME_LIMIT=30 php bench.php
8283
- LIST_TESTS=0/1
8384
- SYSTEM_INFO=0/1
8485
- RUN_TESTS=test1,test2,...
86+
- SKIP_TESTS=test1,test2,...
8587

8688
#### Дополнительно (утилиты в Linux)
8789

@@ -110,6 +112,7 @@ env PHP_MEMORY_LIMIT=64 PHP_TIME_LIMIT=30 php bench.php
110112
- list_tests=0/1
111113
- system_info=0/1
112114
- run_tests=test1,test2,...
115+
- skip_tests=test1,test2,...
113116

114117
### Учет параметров хостинга
115118

‎bench.php‎

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@
146146

147147
$showOnlySystemInfo = 0;
148148

149-
$selectedTests = array();
149+
$selectedTests = array();// exact names
150+
$skipTests = array();// patterns to match names
150151

151152

152153
/* ----------------- Fetch environ or GET params */
@@ -230,6 +231,13 @@
230231
$selectedTests = explode(',', $_GET['run_tests']);
231232
}
232233

234+
if ($r = getenv('SKIP_TESTS')) {
235+
$skipTests = explode(',', $r);
236+
}
237+
if (!empty($_GET['skip_tests'])) {
238+
$skipTests = explode(',', $_GET['skip_tests']);
239+
}
240+
233241

234242

235243
/* common functions */
@@ -306,6 +314,7 @@ function gethostname() {
306314
$shortopts .= "m:"; // Обязательное значение
307315
$shortopts .= "t:"; // Обязательное значение
308316
$shortopts .= "T:"; // Обязательное значение
317+
$shortopts .= "S:"; // Обязательное значение
309318

310319
$longopts = array(
311320
"help",
@@ -320,6 +329,7 @@ function gethostname() {
320329
"memory-limit:", // Обязательное значение
321330
"time-limit:", // Обязательное значение
322331
"run-test:", // Обязательное значение
332+
"skip-test:", // Обязательное значение
323333
);
324334

325335
$hasLongOpts = true;
@@ -409,7 +419,7 @@ function gethostname() {
409419
PHP_EOL
410420
. 'PHP Benchmark Performance Script, version ' . $scriptVersion . PHP_EOL
411421
. PHP_EOL
412-
. '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]' . PHP_EOL
422+
. '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
413423
. PHP_EOL
414424
. ' -h|--help - print this help and exit' . PHP_EOL
415425
. ' -x|--debug - enable debug mode, raise output level' . PHP_EOL
@@ -423,6 +433,7 @@ function gethostname() {
423433
. ' -m|--memory-limit <Mb> - set memory_limit value in Mb, defaults to 130 (Mb)' . PHP_EOL
424434
. ' -t|--time-limit <sec> - set max_execution_time value in seconds, defaults to 600 (sec)' . PHP_EOL
425435
. ' -T|--run-test <name> - run selected tests, test names from --list-tests output, can be defined multiple times' . PHP_EOL
436+
. ' -S|--skip-test <pattern> - skip selected tests, test names pattern to match name from --list-tests output, can be defined multiple times' . PHP_EOL
426437
. PHP_EOL
427438
. 'Example: php ' . basename(__FILE__) . ' -m=64 -t=30' . PHP_EOL
428439
. PHP_EOL
@@ -446,6 +457,7 @@ function gethostname() {
446457
. ' -m <Mb> - set memory_limit value in Mb, defaults to 130 (Mb)' . PHP_EOL
447458
. ' -t <sec> - set max_execution_time value in seconds, defaults to 600 (sec)' . PHP_EOL
448459
. ' -T <name> - run selected tests, test names from -L output, can be defined multiple times' . PHP_EOL
460+
. ' -S <pattern> - skip selected tests, test names pattern to match name from -L output, can be defined multiple times' . PHP_EOL
449461
. PHP_EOL
450462
. 'Example: php ' . basename(__FILE__) . ' -m 64 -t 30' . PHP_EOL
451463
. PHP_EOL
@@ -487,6 +499,17 @@ function gethostname() {
487499
break;
488500

489501

502+
case 'S':
503+
case 'skip-test':
504+
// Multiple values are joined into array
505+
if (!empty($oval)) {
506+
$skipTests = (array)$oval;
507+
} else {
508+
print_pre("{$colorYellow}<<< WARNING >>>{$colorReset} Option '$okey' has no value! Skip." . PHP_EOL);
509+
}
510+
break;
511+
512+
490513
case 'd':
491514
case 'dont-recalc':
492515
case 'x':
@@ -744,7 +767,7 @@ function gethostname() {
744767
'36_02_zlib_gzip_compress' => 500000,
745768
'36_bzip2_compress' => 50000,
746769
'36_lz4_compress' => 5000000,
747-
'36_snappy_compress' => 5000000,
770+
'36_snappy_compress' => 5000000,
748771
'36_zstd_compress' => 5000000,
749772
'36_brotli_compress' => 1000000,
750773
'37_01_php8_str_ccontains' => 100000,
@@ -802,7 +825,7 @@ function gethostname() {
802825
'36_02_zlib_gzip_compress' => 4,
803826
'36_bzip2_compress' => 4,
804827
'36_lz4_compress' => 4,
805-
'36_snappy_compress' => 4,
828+
'36_snappy_compress' => 4,
806829
'36_zstd_compress' => 4,
807830
'36_brotli_compress' => 4,
808831
'37_01_php8_str_ccontains' => 4,
@@ -1463,38 +1486,6 @@ function format_result_test($diffSeconds, $opCount, $memory = 0)
14631486
}
14641487
exit(1);
14651488
}
1466-
/*
1467-
if (is_file('php-gd.inc')) {
1468-
if (extension_loaded('gd')) {
1469-
include_once 'php-gd.inc';
1470-
} else {
1471-
print_pre("${line}\n{$colorYellow}<<< WARNING >>>{$colorReset} Extension 'gd' not loaded or not compiled! Image manipulation tests will be skipped!\n$line");
1472-
}
1473-
} else {
1474-
print_pre("$line\n{$colorRed}<<< ERROR >>>{$colorReset}\nMissing file 'php-gd.inc' with common tests!\n$line");
1475-
if ($printJson) {
1476-
print("\"messages_count\": {$messagesCnt},\n");
1477-
print("\"end\":true\n}" . PHP_EOL);
1478-
}
1479-
exit(1);
1480-
}
1481-
*/
1482-
/*
1483-
if (is_file('php-imagick.inc')) {
1484-
if (extension_loaded('imagick')) {
1485-
include_once 'php-imagick.inc';
1486-
} else {
1487-
print_pre("${line}\n{$colorYellow}<<< WARNING >>>{$colorReset} Extension 'imagick' not loaded or not compiled! Image manipulation tests will be skipped!\n$line");
1488-
}
1489-
} else {
1490-
print_pre("$line\n{$colorRed}<<< ERROR >>>{$colorReset}\nMissing file 'php-imagick.inc' with common tests!\n$line");
1491-
if ($printJson) {
1492-
print("\"messages_count\": {$messagesCnt},\n");
1493-
print("\"end\":true\n}" . PHP_EOL);
1494-
}
1495-
exit(1);
1496-
}
1497-
*/
14981489
if ((int)$phpversion[0] >= 5) {
14991490
if (is_file('php5.inc')) {
15001491
include_once 'php5.inc';
@@ -1520,8 +1511,33 @@ function format_result_test($diffSeconds, $opCount, $memory = 0)
15201511
}
15211512

15221513
$functions = get_defined_functions();
1523-
sort($functions['user']);
1514+
$availableFunctions =$functions['user'];
1515+
sort($availableFunctions);
15241516

1517+
// fiter out tests
1518+
function filter_out_name_by_pattern($key)
1519+
{
1520+
global $skipTests, $debugMode, $availableFunctions;
1521+
$var = $availableFunctions[$key];
1522+
$ret = 1;
1523+
foreach ($skipTests as $pattern){
1524+
// simple test - str in name
1525+
$c=strpos($var,$pattern);
1526+
if ($debugMode) {
1527+
$d=var_export($c,true);
1528+
print("Search '$pattern' inside '$var':$d\n");
1529+
}
1530+
if ($c!==false) {
1531+
$ret = 0;
1532+
break;
1533+
};
1534+
}
1535+
//nothing found - not skipping
1536+
if ($debugMode) print("Will return $ret\n");
1537+
if (!$ret) unset($availableFunctions[$key]);
1538+
return $ret;
1539+
}
1540+
if ($skipTests) array_filter($availableFunctions, "filter_out_name_by_pattern",ARRAY_FILTER_USE_KEY);
15251541
/** ------------------------------- Early checks ------------------------------- */
15261542

15271543
if ($outputTestsList) {
@@ -1530,7 +1546,7 @@ function format_result_test($diffSeconds, $opCount, $memory = 0)
15301546
print("<pre>");
15311547
}
15321548
print("\nAvailable tests:\n");
1533-
foreach ($functions['user'] as $user) {
1549+
foreach ($availableFunctions as $user) {
15341550
if (strpos($user, 'test_') === 0) {
15351551
$testName = str_replace('test_', '', $user);
15361552
print($testName . PHP_EOL);
@@ -1542,7 +1558,7 @@ function format_result_test($diffSeconds, $opCount, $memory = 0)
15421558
} else {
15431559
print("tests: [".PHP_EOL);
15441560
$a = array();
1545-
foreach ($functions['user'] as $user) {
1561+
foreach ($availableFunctions as $user) {
15461562
if (strpos($user, 'test_') === 0) {
15471563
$testName = str_replace('test_', '', $user);
15481564
$a[] = $testName;
@@ -1692,6 +1708,7 @@ function print_results_common()
16921708
{
16931709
$total = 0;
16941710

1711+
global $availableFunctions;
16951712
global $line, $padHeader, $cpuInfo, $padInfo, $scriptVersion, $maxTime, $originTimeLimit, $originMemoryLimit, $cryptAlgoName, $memoryLimitMb;
16961713
global $flushStr, $has_apc, $has_pcre, $has_intl, $has_json, $has_simplexml, $has_dom, $has_mbstring, $has_opcache, $has_xcache;
16971714
global $has_gd, $has_imagick, $has_igb, $has_msg, $has_jsond, $has_jsond_as_json;
@@ -1765,7 +1782,7 @@ function print_results_common()
17651782
. "$line\n" . $flushStr;
17661783
flush();
17671784

1768-
foreach ($functions['user'] as $user) {
1785+
foreach ($availableFunctions as $user) {
17691786
if (strpos($user, 'test_') === 0) {
17701787
$testName = str_replace('test_', '', $user);
17711788
if ($runOnlySelectedTests) {
@@ -1811,6 +1828,7 @@ function print_results_machine()
18111828
{
18121829
$total = 0;
18131830

1831+
global $availableFunctions;
18141832
global $scriptVersion, $showOnlySystemInfo, $rawValues4json;
18151833
global $functions, $runOnlySelectedTests, $selectedTests, $totalOps;
18161834

@@ -1831,7 +1849,7 @@ function print_results_machine()
18311849

18321850
$rawValues4json = true;
18331851

1834-
foreach ($functions['user'] as $user) {
1852+
foreach ($availableFunctions as $user) {
18351853
if (strpos($user, 'test_') === 0) {
18361854
$testName = str_replace('test_', '', $user);
18371855
if ($runOnlySelectedTests) {
@@ -1861,6 +1879,7 @@ function print_results_json()
18611879
{
18621880
$total = 0;
18631881

1882+
global $availableFunctions;
18641883
global $scriptVersion, $showOnlySystemInfo, $rawValues4json, $messagesCnt;
18651884
global $functions, $runOnlySelectedTests, $selectedTests, $totalOps;
18661885

@@ -1883,7 +1902,7 @@ function print_results_json()
18831902
$rawValues4json = true;
18841903

18851904
echo "\"rows\": [\n";
1886-
foreach ($functions['user'] as $user) {
1905+
foreach ($availableFunctions as $user) {
18871906
if (strpos($user, 'test_') === 0) {
18881907
$testName = str_replace('test_', '', $user);
18891908
if ($runOnlySelectedTests) {

0 commit comments

Comments
(0)

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