Skip to content

Commit ad67970

Browse files
Issue #20
- add test for sodium Add test for ctypeÄ
1 parent 4dba8de commit ad67970

10 files changed

+131
-33
lines changed

bench.php

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Author : Sergey Dryabzhinsky #
1111
# Company : Rusoft Ltd, Russia #
1212
# Date : Jun 4, 2025 #
13-
# Version : 1.0.63 #
13+
# Version : 1.0.64-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.63';
23+
$scriptVersion = '1.0.64-dev';
2424

2525
// Special string to flush buffers, nginx for example
2626
$flushStr = '<!-- '.str_repeat(" ", 8192).' -->';
@@ -102,6 +102,9 @@
102102
if (extension_loaded('intl')) {
103103
@include_once("intl.inc");
104104
}
105+
if (extension_loaded('ctype')) {
106+
@include_once("mod-ctype-isdigit.inc");
107+
}
105108
if (file_exists('UUID.php') && PHP_VERSION >= '5.0.0') {
106109
@include_once("php-uuid.inc");
107110
}
@@ -125,12 +128,19 @@
125128
if (file_exists('kvstorage-redis.inc') && extension_loaded('redis')) {
126129
@include_once("kv-redis.inc");
127130
}
131+
}// php>=5.0
132+
if ( PHP_VERSION >= '5.3.0') {
128133
if (file_exists('kvstorage-sqlite3.inc') && extension_loaded('sqlite3')) {
129134
@include_once("kv-sqlite3-generic-file.inc");
130135
@include_once("kv-sqlite3-devshm-file.inc");
131136
@include_once("kv-sqlite3-memory-file.inc");
132137
}
133-
}// php>=5.0
138+
}// php>=5.3
139+
if ( PHP_VERSION >= '7.2.0') {
140+
if (file_exists('mod-sodium.inc') && extension_loaded('sodium')) {
141+
@include_once("mod-sodium.inc");
142+
}
143+
}// php>=5.3
134144

135145
if (extension_loaded('uuid')) {
136146
@include_once("mod-uuid.inc");
@@ -715,25 +725,25 @@ function gethostname() {
715725
/** ---------------------------------- Tests limits - to recalculate -------------------------------------------- */
716726

717727
// Gathered on this machine
718-
$loopMaxPhpTimesMHz = 3800;
728+
$loopMaxPhpTimesMHz = 3500;
719729
// How much time needed for tests on this machine
720730
$loopMaxPhpTimes = array(
721-
'4.4' => 324,
722-
'5.2' => 248,
723-
'5.3' => 211,
724-
'5.4' => 199,
725-
'5.5' => 200,
726-
'5.6' => 204,
727-
'7.0' => 106,
728-
'7.1' => 104,
729-
'7.2' => 98,
730-
'7.3' => 89,
731-
'7.4' => 89,
732-
'8.0' => 83,
733-
'8.1' => 82,
734-
'8.2' => 79,
735-
'8.3' => 77,
736-
'8.4' => 77
731+
'4.4' => 1456,
732+
'5.2' => 839,
733+
'5.3' => 1235,
734+
'5.4' => 1510,
735+
'5.5' => 802,
736+
'5.6' => 1337,
737+
'7.0' => 672,
738+
'7.1' => 669,
739+
'7.2' => 662,
740+
'7.3' => 586,
741+
'7.4' => 659,
742+
'8.0' => 676,
743+
'8.1' => 450,
744+
'8.2' => 427,
745+
'8.3' => 582,
746+
'8.4' => 736
737747
);
738748
// Simple and fast test times, used to adjust all test times and limits
739749
$dumbTestMaxPhpTimes = array(
@@ -807,8 +817,8 @@ function gethostname() {
807817
'36_snappy_compress' => 5000000,
808818
'36_zstd_compress' => 5000000,
809819
'36_brotli_compress' => 1000000,
810-
'37_01_php8_str_ccontains' => 100000,
811-
'37_02_php8_str_ccontains_simulate' => 100000,
820+
'37_01_php8_str_contains' => 100000,
821+
'37_02_php8_str_contains_emulate' => 100000,
812822
'38_01_php_uuid' => 1000000,
813823
'38_02_mod_uuid' => 1000000,
814824
'39_01_kvstorage_memory' => 500000,
@@ -825,6 +835,9 @@ function gethostname() {
825835
'40_03_gd_save_fill_empty_jpg' => 10000,
826836
'40_04_gd_save_fill_empty_webp' => 10000,
827837
'40_05_gd_save_fill_empty_avif' => 10000,
838+
'41_01_sodium_string_num_int' => 10000000,
839+
'41_02_sodium_string_num_float' => 10000000,
840+
'42_ctype_isdigit' => 10000000,
828841
);
829842
// Should not be more than X Mb
830843
// Different PHP could use different amount of memory
@@ -879,8 +892,8 @@ function gethostname() {
879892
'36_snappy_compress' => 4,
880893
'36_zstd_compress' => 4,
881894
'36_brotli_compress' => 4,
882-
'37_01_php8_str_ccontains' => 4,
883-
'37_02_php8_str_ccontains_simulate' => 4,
895+
'37_01_php8_str_contains' => 4,
896+
'37_02_php8_str_contains_simulate' => 4,
884897
'38_01_php_uuid' => 4,
885898
'38_02_mod_uuid' => 4,
886899
'39_01_kvstorage_memory' => 3,
@@ -897,6 +910,9 @@ function gethostname() {
897910
'40_03_gd_save_fill_empty_jpg' => 4,
898911
'40_04_gd_save_fill_empty_webp' => 4,
899912
'40_05_gd_save_fill_empty_avif' => 4,
913+
'41_01_sodium_string_num_int' => 4,
914+
'41_02_sodium_string_num_float' => 4,
915+
'42_ctype_isdigit' => 4,
900916
);
901917

902918
/** ---------------------------------- Common functions -------------------------------------------- */
@@ -1707,6 +1723,10 @@ function filter_out_name_by_pattern($key)
17071723
if (extension_loaded('shmop')) {
17081724
$has_shmop = "{$colorGreen}yes{$colorReset}";
17091725
}
1726+
$has_sodium = "{$colorYellow}no{$colorReset}";
1727+
if (extension_loaded('sodium')) {
1728+
$has_sodium = "{$colorGreen}yes{$colorReset}";
1729+
}
17101730
$has_memcache = "{$colorYellow}no{$colorReset}";
17111731
if (extension_loaded('memcache')) {
17121732
$has_memcache = "{$colorGreen}yes{$colorReset}";
@@ -1796,6 +1816,10 @@ function filter_out_name_by_pattern($key)
17961816
if (extension_loaded('intl')) {
17971817
$has_intl = "{$colorGreen}yes{$colorReset}";
17981818
}
1819+
$has_ctype = "{$colorYellow}no{$colorReset}";
1820+
if (extension_loaded('ctype')) {
1821+
$has_ctype = "{$colorGreen}yes{$colorReset}";
1822+
}
17991823
$has_zlib = "{$colorYellow}no{$colorReset}";
18001824
$has_gzip = "{$colorYellow}no{$colorReset}";
18011825
if (extension_loaded('zlib')) {
@@ -1845,6 +1869,7 @@ function filter_out_name_by_pattern($key)
18451869
if (!defined('REDIS_VERSION')) define('REDIS_VERSION', '-.--');
18461870
if (!defined('SQLITE3_VERSION')) define('SQLITE3_VERSION', '-.--');
18471871
if (!defined('LIBXML_DOTTED_VERSION')) define('LIBXML_DOTTED_VERSION', '-.-.-');
1872+
if (!defined('SODIUM_LIBRARY_VERSION')) define('SODIUM_LIBRARY_VERSION', '-.-.-');
18481873
if (!defined('INTL_ICU_VERSION')) define('INTL_ICU_VERSION', '-.-');
18491874
if (!defined('LIBZSTD_VERSION_STRING')) define('LIBZSTD_VERSION_STRING', '-.-.-');
18501875

@@ -1856,9 +1881,9 @@ function print_results_common()
18561881
global $line, $padHeader, $cpuInfo, $padInfo, $scriptVersion, $maxTime, $originTimeLimit, $originMemoryLimit, $cryptAlgoName, $memoryLimitMb;
18571882
global $flushStr, $has_apc, $has_pcre, $has_intl, $has_json, $has_simplexml, $has_dom, $has_mbstring, $has_opcache, $has_xcache;
18581883
global $has_gd, $has_gdgif, $has_gdpng, $has_gdjpg, $has_gdwebp, $has_gdavif;
1859-
global $has_imagick, $has_igb, $has_msg, $has_jsond, $has_jsond_as_json;
1884+
global $has_imagick, $has_igb, $has_msg, $has_jsond, $has_jsond_as_json, $has_ctype;
18601885
global $has_zlib, $has_uuid, $has_gzip, $has_bz2, $has_lz4, $has_snappy, $has_zstd, $has_brotli;
1861-
global $has_apcu, $has_shmop, $has_memcache, $has_redis, $has_sqlite3, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
1886+
global $has_apcu, $has_shmop, $has_memcache, $has_redis, $has_sodium, $has_sqlite3, $opcache, $has_eacc, $has_xdebug, $xcache, $apcache, $eaccel, $xdebug, $xdbg_mode, $obd_set, $mbover;
18621887
global $showOnlySystemInfo, $padLabel, $functions, $runOnlySelectedTests, $selectedTests, $totalOps;
18631888
global $colorGreen, $colorReset, $colorRed;
18641889

@@ -1890,6 +1915,7 @@ function print_results_common()
18901915
. str_pad("pcre", $padInfo, ' ', STR_PAD_LEFT) . " : $has_pcre" . ($has_pcre == "{$colorGreen}yes{$colorReset}" ? '; version: ' . PCRE_VERSION : '') . "\n"
18911916
. str_pad("simplexml", $padInfo, ' ', STR_PAD_LEFT) . " : $has_simplexml; libxml version: ".LIBXML_DOTTED_VERSION."\n"
18921917
. str_pad("dom", $padInfo, ' ', STR_PAD_LEFT) . " : $has_dom\n"
1918+
. str_pad("ctype", $padInfo, ' ', STR_PAD_LEFT) . " : $has_ctype\n"
18931919
. str_pad("intl", $padInfo, ' ', STR_PAD_LEFT) . " : $has_intl" . ($has_intl == "{$colorGreen}yes{$colorReset}" ? '; icu version: ' . INTL_ICU_VERSION : '')."\n"
18941920
. str_pad("-optional->", $padInfo, ' ', STR_PAD_LEFT) . "\n"
18951921
. str_pad("gd", $padInfo, ' ', STR_PAD_LEFT) . " : $has_gd: version: ". GD_VERSION."\n"
@@ -1904,6 +1930,7 @@ function print_results_common()
19041930
. str_pad("memcache", $padInfo, ' ', STR_PAD_LEFT) . " : $has_memcache, version: ".MEMCACHE_VERSION.";\n"
19051931
. str_pad("redis", $padInfo, ' ', STR_PAD_LEFT) . " : $has_redis, version: ".REDIS_VERSION.";\n"
19061932
. str_pad("sqlite3", $padInfo, ' ', STR_PAD_LEFT) . " : $has_sqlite3, version: ".SQLITE3_VERSION.";\n"
1933+
. str_pad("sodium", $padInfo, ' ', STR_PAD_LEFT) . " : $has_sodium, version: ".SODIUM_LIBRARY_VERSION.";\n"
19071934
. str_pad("-alternative->", $padInfo, ' ', STR_PAD_LEFT) . "\n"
19081935
. str_pad("igbinary", $padInfo, ' ', STR_PAD_LEFT) . " : $has_igb\n"
19091936
. str_pad("msgpack", $padInfo, ' ', STR_PAD_LEFT) . " : $has_msg\n"

kv-sqlite3-devshm-file.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* php safe options - only tests mod sqlite3
4-
* Php 5.0+
4+
* Php 5.3+
55
*/
66

77
/** ---------------------------------- Tests functions -------------------------------------------- */

kv-sqlite3-generic-file.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* php safe options - only tests mod sqlite3
4-
* Php 5.0+
4+
* Php 5.3+
55
*/
66

77
/** ---------------------------------- Tests functions -------------------------------------------- */

kv-sqlite3-memory-file.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* php safe options - only tests mod sqlite3
4-
* Php 5.0+
4+
* Php 5.3+
55
*/
66

77
/** ---------------------------------- Tests functions -------------------------------------------- */

kvstorage-shmop.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ class KVStorageShmop
2222

2323
public function set($key, $value, $timeout=60){
2424
$id=shmop_open($key, "a", 0, 0);
25+
if ($id===false) return false;
2526
$ret=shmop_write($id, $value, 0);
2627
shmop_close($id);
2728
return $ret;
2829
}
2930

3031
public function get($key, $default=null){
3132
$id=shmop_open($key, "a", 0, 0);
33+
if ($id===false) return false;
3234
$size=shmop_size($id);
3335
$ret=shmop_read($id,0,$size);
3436
shmop_close($id);
@@ -37,6 +39,7 @@ class KVStorageShmop
3739

3840
public function del($key){
3941
$id=shmop_open($key, "a", 0, 0);
42+
if ($id===false) return false;
4043
$ret=shmop_delete($id);
4144
shmop_close($id);
4245
return $ret;

kvstorage-sqlite3.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* mod-sqlite3
4-
* Php 5.2+
4+
* Php 5.3+
55
*/
66

77
class KVStorageSqlite3

mod-ctype-isdigit.inc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* module ctype test functions
4+
* Php 4.0
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
function test_42_ctype_isdigit()
10+
{
11+
global $stringTest, $emptyResult, $testsLoopLimits, $totalOps;
12+
13+
if (!function_exists('ctype_digit')) {
14+
return $emptyResult;
15+
}
16+
17+
$count = $testsLoopLimits['42_ctype_isdigit'];
18+
$time_start = get_microtime();
19+
$s=''.time();
20+
$d=0;
21+
for ($i = 0; $i < $count; $i++) {
22+
if (ctype_digit($s)) $d++;
23+
}
24+
$totalOps += $count;
25+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
26+
}

mod-sodium.inc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* module sodium test functions
4+
* Php 7.2+
5+
*/
6+
7+
/** ---------------------------------- Tests functions -------------------------------------------- */
8+
9+
function test_41_01_sodium_string_num_int()
10+
{
11+
global $stringTest, $emptyResult, $testsLoopLimits, $totalOps;
12+
13+
if (!function_exists('sodium_increment')) {
14+
return $emptyResult;
15+
}
16+
$count = $testsLoopLimits['41_01_sodium_string_num_int'];
17+
$time_start = get_microtime();
18+
$num=''.time();
19+
for ($i = 0; $i < $count; $i++) {
20+
sodium_increment($num);
21+
}
22+
$totalOps += $count;
23+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
24+
}
25+
26+
function test_41_02_sodium_string_num_float()
27+
{
28+
global $stringTest, $emptyResult, $testsLoopLimits, $totalOps;
29+
30+
if (!function_exists('sodium_increment')) {
31+
return $emptyResult;
32+
}
33+
$count = $testsLoopLimits['41_02_sodium_string_num_float'];
34+
$time_start = get_microtime();
35+
$num=''.microtime(true);
36+
for ($i = 0; $i < $count; $i++) {
37+
sodium_increment($num);
38+
}
39+
$totalOps += $count;
40+
return format_result_test(get_microtime() - $time_start, $count, mymemory_usage());
41+
}

php8.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ function test_37_01_php8_Str_Contains()
2727
return format_result_test(get_microtime() - $time_start, $count , $memory);
2828
}
2929

30-
function test_37_02_php8_Str_Contains_Simulate()
30+
function test_37_02_php8_Str_Contains_emulate()
3131
{
3232
global $testsLoopLimits, $totalOps;
3333

34-
$count = $testsLoopLimits['37_02_php8_str_contains_simulate'];
34+
$count = $testsLoopLimits['37_02_php8_str_contains_emulate'];
3535
$time_start = get_microtime();
3636
$s = "Foobar";
3737
$n = "Foo";

sqlite3.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
function get_sqlite3_object()
99
{
10-
global $sqlite3_dbpath=':memory:', $debugMode;
10+
global $sqlite3_dbpat, $debugMode;
1111
if ($debugMode) var_dump($sqlite3_dbpath);
12+
if (!$sqlite3_dbpath) $sqlite3_dbpath=':memory:';
1213
static $s=null;
1314
if ($s!==null){$s->close(); $s=null;}
1415
if ($s===null)

0 commit comments

Comments
 (0)