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 ca32be5

Browse files
Merge pull request 'issue-12-keyvalue-memory' (#14) from issue-12-keyvalue-memory into master
Reviewed-on: https://gitea.rusoft.ru/open-source/php-simple-benchmark-script/pulls/14
2 parents a2da094 + 87fcee6 commit ca32be5

18 files changed

+622
-12
lines changed

‎CHANGELOG.md

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

3+
@ 2025年06月02日, v1.0.61
4+
5+
* Added simple key-value tests:memory and xcache, apcu, shmop, memcache, redis
6+
* Test selected-run by pattern now not exact name
7+
38
@ 2025年05月30日, v1.0.60
49

510
* Added ability to skip tests by name pattern

‎bench.php

Lines changed: 103 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Author : Sergey Dryabzhinsky #
1111
# Company : Rusoft Ltd, Russia #
1212
# Date : May 29, 2025 #
13-
# Version : 1.0.60-dev #
13+
# Version : 1.0.61-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.60-dev';
23+
$scriptVersion = '1.0.61-dev';
2424

2525
// Special string to flush buffers, nginx for example
2626
$flushStr = '<!-- '.str_repeat("", 8192).' -->';
@@ -105,6 +105,28 @@
105105
if (file_exists('UUID.php') && PHP_VERSION >= '5.0.0') {
106106
@include_once("php-uuid.inc");
107107
}
108+
if ( PHP_VERSION >= '5.0.0') {
109+
110+
if (file_exists('kvstorage-mem.inc')) {
111+
@include_once("kv-memory.inc");
112+
}
113+
if (file_exists('kvstorage-xcache.inc') && extension_loaded('xCache')) {
114+
@include_once("kv-xcache.inc");
115+
}
116+
if (file_exists('kvstorage-apcu.inc') && extension_loaded('apcu')) {
117+
@include_once("kv-apcu.inc");
118+
}
119+
if (file_exists('kvstorage-shmop.inc') && extension_loaded('shmop')) {
120+
@include_once("kv-shmop.inc");
121+
}
122+
if (file_exists('kvstorage-memcache.inc') && extension_loaded('memcache')) {
123+
@include_once("kv-memcache.inc");
124+
}
125+
if (file_exists('kvstorage-redis.inc') && extension_loaded('redis')) {
126+
@include_once("kv-redis.inc");
127+
}
128+
}// php>=5.0
129+
108130
if (extension_loaded('uuid')) {
109131
@include_once("mod-uuid.inc");
110132
}
@@ -432,7 +454,7 @@ function gethostname() {
432454
. ' -I|--system-info - output system info but do not run tests and exit' . PHP_EOL
433455
. ' -m|--memory-limit <Mb> - set memory_limit value in Mb, defaults to 130 (Mb)' . PHP_EOL
434456
. ' -t|--time-limit <sec> - set max_execution_time value in seconds, defaults to 600 (sec)' . PHP_EOL
435-
. ' -T|--run-test <name> - run selected tests, test names from --list-tests output, can be defined multiple times' . PHP_EOL
457+
. ' -T|--run-test <pattern> - run selected tests, test names from --list-tests output, can be defined multiple times' . PHP_EOL
436458
. ' -S|--skip-test <pattern> - skip selected tests, test names pattern to match name from --list-tests output, can be defined multiple times' . PHP_EOL
437459
. PHP_EOL
438460
. 'Example: php ' . basename(__FILE__) . ' -m=64 -t=30' . PHP_EOL
@@ -456,7 +478,7 @@ function gethostname() {
456478
. ' -I - output system info but do not run tests and exit' . PHP_EOL
457479
. ' -m <Mb> - set memory_limit value in Mb, defaults to 130 (Mb)' . PHP_EOL
458480
. ' -t <sec> - set max_execution_time value in seconds, defaults to 600 (sec)' . PHP_EOL
459-
. ' -T <name> - run selected tests, test names from -L output, can be defined multiple times' . PHP_EOL
481+
. ' -T <pattern> - run selected tests, test names from -L output, can be defined multiple times' . PHP_EOL
460482
. ' -S <pattern> - skip selected tests, test names pattern to match name from -L output, can be defined multiple times' . PHP_EOL
461483
. PHP_EOL
462484
. 'Example: php ' . basename(__FILE__) . ' -m 64 -t 30' . PHP_EOL
@@ -567,14 +589,19 @@ function gethostname() {
567589
$tz = ini_get('date.timezone');
568590
if (!$tz) ini_set('date.timezone', 'Europe/Moscow');
569591

570-
ini_set('display_errors', 0);
571592
@ini_set('error_log', null);
572593
ini_set('implicit_flush', 1);
573594
ini_set('output_buffering', 0);
574595
ob_implicit_flush(1);
575596

576-
// Disable explicit error reporting
577-
error_reporting(E_ERROR | E_WARNING | E_PARSE);
597+
if ($debugMode){
598+
ini_set('display_errors', 1);
599+
error_reporting(E_ERROR | E_WARNING | E_PARSE);
600+
} else {
601+
ini_set('display_errors', 0);
602+
// Disable explicit error reporting
603+
error_reporting(E_ERROR | E_WARNING | E_PARSE);
604+
}
578605

579606
// Check XDebug
580607
$xdebug = (int)ini_get('xdebug.default_enable');
@@ -774,6 +801,12 @@ function gethostname() {
774801
'37_02_php8_str_ccontains_simulate' => 100000,
775802
'38_01_php_uuid' => 1000000,
776803
'38_02_mod_uuid' => 1000000,
804+
'39_01_kvstorage_memory' => 500000,
805+
'39_02_kvstorage_xcache' => 500000,
806+
'39_03_kvstorage_apcu' => 500000,
807+
'39_04_kvstorage_shmop' => 500000,
808+
'39_05_kvstorage_memcache' => 500000,
809+
'39_06_kvstorage_redis' => 500000,
777810
);
778811
// Should not be more than X Mb
779812
// Different PHP could use different amount of memory
@@ -832,6 +865,12 @@ function gethostname() {
832865
'37_02_php8_str_ccontains_simulate' => 4,
833866
'38_01_php_uuid' => 4,
834867
'38_02_mod_uuid' => 4,
868+
'39_01_kvstorage_memory' => 3,
869+
'39_02_kvstorage_xcache' => 2,
870+
'39_03_kvstorage_apcu' => 47,
871+
'39_04_kvstorage_shmop' => 70,
872+
'39_05_kvstorage_memcache' => 47,
873+
'39_06_kvstorage_redis' => 47,
835874
);
836875

837876
/** ---------------------------------- Common functions -------------------------------------------- */
@@ -1514,6 +1553,29 @@ function format_result_test($diffSeconds, $opCount, $memory = 0)
15141553
$availableFunctions =$functions['user'];
15151554
sort($availableFunctions);
15161555

1556+
// fiter in tests
1557+
function filter_in_name_by_pattern($key)
1558+
{
1559+
global $selectedTests, $debugMode, $availableFunctions;
1560+
$var = $availableFunctions[$key];
1561+
$ret = 0;
1562+
foreach ($selectedTests as $pattern){
1563+
// simple test - str in name
1564+
$c=strpos($var,$pattern);
1565+
if ($debugMode) {
1566+
$d=var_export($c,true);
1567+
print("Search '$pattern' inside '$var':$d\n");
1568+
}
1569+
if ($c!==false) {
1570+
$ret = 1;
1571+
break;
1572+
};
1573+
}
1574+
//nothing found - skipping
1575+
if ($debugMode) print("Will return $ret\n");
1576+
if (!$ret) unset($availableFunctions[$key]);
1577+
return $ret;
1578+
}
15171579
// fiter out tests
15181580
function filter_out_name_by_pattern($key)
15191581
{
@@ -1537,6 +1599,7 @@ function filter_out_name_by_pattern($key)
15371599
if (!$ret) unset($availableFunctions[$key]);
15381600
return $ret;
15391601
}
1602+
if ($selectedTests) array_filter($availableFunctions, "filter_in_name_by_pattern",ARRAY_FILTER_USE_KEY);
15401603
if ($skipTests) array_filter($availableFunctions, "filter_out_name_by_pattern",ARRAY_FILTER_USE_KEY);
15411604
/** ------------------------------- Early checks ------------------------------- */
15421605

@@ -1588,7 +1651,7 @@ function filter_out_name_by_pattern($key)
15881651
$has_json = "{$colorRed}no{$colorReset}";
15891652
if ($printJson) {
15901653
print_pre("{$colorRed}<<< ERROR >>>{$colorReset} Extension 'json' is mandatory for JSON output!");
1591-
print("\"messages_count\": {$messagesCnt},\n");
1654+
print("\"messag0es_count\": {$messagesCnt},\n");
15921655
print("\"end\":true\n}" . PHP_EOL);
15931656
exit(-1);
15941657
}
@@ -1602,14 +1665,38 @@ function filter_out_name_by_pattern($key)
16021665
if (extension_loaded('Zend OPcache')) {
16031666
$has_opcache = "{$colorYellow}yes{$colorReset}";
16041667
}
1605-
$has_xcache = "{$colorGreen}no{$colorReset}";
1668+
$has_xcache = "{$colorYellow}no{$colorReset}";
16061669
if (extension_loaded('XCache')) {
16071670
$has_xcache = "{$colorYellow}yes{$colorReset}";
16081671
}
16091672
$has_apc = "{$colorGreen}no{$colorReset}";
16101673
if (extension_loaded('apc')) {
16111674
$has_apc = "{$colorYellow}yes{$colorReset}";
16121675
}
1676+
$has_apcu = "{$colorYellow}no{$colorReset}";
1677+
if (extension_loaded('apcu')) {
1678+
$has_apcu = "{$colorGreen}yes{$colorReset}";
1679+
}
1680+
$has_shmop = "{$colorYellow}no{$colorReset}";
1681+
if (extension_loaded('shmop')) {
1682+
$has_shmop = "{$colorGreen}yes{$colorReset}";
1683+
}
1684+
$has_memcache = "{$colorYellow}no{$colorReset}";
1685+
if (extension_loaded('memcache')) {
1686+
$has_memcache = "{$colorGreen}yes{$colorReset}";
1687+
include_once('memcache.inc');
1688+
$v=get_memcached_version();
1689+
if ($v) define('MEMCACHE_VERSION',$v);
1690+
else define('MEMCACHE_VERSION','-.-.-');
1691+
}
1692+
$has_redis = "{$colorYellow}no{$colorReset}";
1693+
if (extension_loaded('memcache')) {
1694+
$has_redis = "{$colorGreen}yes{$colorReset}";
1695+
include_once('redis.inc');
1696+
$v=get_redis_version();
1697+
if ($v) define('REDIS_VERSION',$v);
1698+
else define('REDIS_VERSION','-.-.-');
1699+
}
16131700
$has_eacc = "{$colorGreen}no{$colorReset}";
16141701
if (extension_loaded('eAccelerator')) {
16151702
$has_eacc = "{$colorYellow}yes{$colorReset}";
@@ -1713,7 +1800,7 @@ function print_results_common()
17131800
global $flushStr, $has_apc, $has_pcre, $has_intl, $has_json, $has_simplexml, $has_dom, $has_mbstring, $has_opcache, $has_xcache;
17141801
global $has_gd, $has_imagick, $has_igb, $has_msg, $has_jsond, $has_jsond_as_json;
17151802
global $has_zlib, $has_uuid, $has_gzip, $has_bz2, $has_lz4, $has_snappy, $has_zstd, $has_brotli;
1716-
global $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
1803+
global $has_apcu, $has_shmop, $has_memcache, $has_redis, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
17171804
global $showOnlySystemInfo, $padLabel, $functions, $runOnlySelectedTests, $selectedTests, $totalOps;
17181805
global $colorGreen, $colorReset, $colorRed;
17191806

@@ -1749,6 +1836,10 @@ function print_results_common()
17491836
. str_pad("-optional->", $padInfo, '', STR_PAD_LEFT) . "\n"
17501837
. str_pad("gd", $padInfo, '', STR_PAD_LEFT) . " : $has_gd: version: ". GD_VERSION."\n"
17511838
. str_pad("imagick", $padInfo, '', STR_PAD_LEFT) . " : $has_imagick: version: ".IMG_VERSION."\n"
1839+
. str_pad("apcu", $padInfo, '', STR_PAD_LEFT) . " : $has_apcu;\n"
1840+
. str_pad("shmop", $padInfo, '', STR_PAD_LEFT) . " : $has_shmop;\n"
1841+
. str_pad("memcache", $padInfo, '', STR_PAD_LEFT) . " : $has_memcache, version: ".MEMCACHE_VERSION.";\n"
1842+
. str_pad("redis", $padInfo, '', STR_PAD_LEFT) . " : $has_redis, version: ".REDIS_VERSION.";\n"
17521843
. str_pad("-alternative->", $padInfo, '', STR_PAD_LEFT) . "\n"
17531844
. str_pad("igbinary", $padInfo, '', STR_PAD_LEFT) . " : $has_igb\n"
17541845
. str_pad("msgpack", $padInfo, '', STR_PAD_LEFT) . " : $has_msg\n"
@@ -1785,11 +1876,11 @@ function print_results_common()
17851876
foreach ($availableFunctions as $user) {
17861877
if (strpos($user, 'test_') === 0) {
17871878
$testName = str_replace('test_', '', $user);
1788-
if ($runOnlySelectedTests) {
1879+
/*if ($runOnlySelectedTests) {
17891880
if (!in_array($testName, $selectedTests)) {
17901881
continue;
17911882
}
1792-
}
1883+
}*/
17931884
echo str_pad($testName, $padLabel) . " :";
17941885
list($resultSec, $resultSecFmt, $resultOps, $resultOpMhz, $memory) = $user();
17951886
$total += $resultSec;

‎kv-apcu.inc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* php safe options - only tests array/class interfaces
4+
* Php 5.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 5.0
13+
*/
14+
function test_39_03_kvstorage_apcu()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
global $debugMode;
18+
19+
if (!is_file('kvstorage-apcu.inc')){
20+
return $emptyResult;
21+
}
22+
23+
include_once('kvstorage-apcu.inc');
24+
if (!$kvstorage->available){
25+
return $emptyResult;
26+
}
27+
28+
$count = $testsLoopLimits['39_03_kvstorage_apcu'];
29+
$time_start = get_microtime();
30+
31+
if ($debugMode) {
32+
var_dump($count);
33+
var_dump($kvstorage);
34+
}
35+
36+
for ($i = 0; $i < $count; $i++) {
37+
$num = $i / 100.;
38+
$kvstorage->set($i, $num);
39+
$v=$kvstorage->get($i);
40+
if ($v===$num) $kvstorage->del($i);
41+
}
42+
$totalOps += $count;
43+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
44+
}

‎kv-memcache.inc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* php safe options - only tests mod memcache
4+
* Php 5.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 5.0
13+
*/
14+
function test_39_05_kvstorage_memcache()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
18+
if (!is_file('kvstorage-memcache.inc')){
19+
return $emptyResult;
20+
}
21+
22+
include_once('kvstorage-memcache.inc');
23+
if (!$kvstorage->available){
24+
return $emptyResult;
25+
}
26+
27+
$count = $testsLoopLimits['39_05_kvstorage_memcache'];
28+
$time_start = get_microtime();
29+
30+
for ($i = 0; $i < $count; $i++) {
31+
$num = $i / 100.;
32+
$kvstorage->set($i, $num);
33+
$v=$kvstorage->get($i);
34+
if ($v===$num) $kvstorage->del($i);
35+
}
36+
$totalOps += $count;
37+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
38+
}

‎kv-memory.inc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* php safe options - only tests array/class interfaces
4+
* Php 5.0+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
// ------------------------- INTL tests -----------------------
10+
11+
/**
12+
* @since 5.0
13+
*/
14+
function test_39_01_kvstorage_memory()
15+
{
16+
global $testsLoopLimits, $totalOps, $emptyResult;
17+
18+
if (!is_file('kvstorage-mem.inc')){
19+
return $emptyResult;
20+
}
21+
22+
include_once('kvstorage-mem.inc');
23+
$count = $testsLoopLimits['39_01_kvstorage_memory'];
24+
$time_start = get_microtime();
25+
26+
for ($i = 0; $i < $count; $i++) {
27+
$num = $i / 100.;
28+
$kvstorage->set($i, $num);
29+
$v=$kvstorage->get($i);
30+
if ($v===$num) $kvstorage->del($i);
31+
}
32+
$totalOps += $count;
33+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
34+
}

0 commit comments

Comments
(0)

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