[php-src] Issue #11997: ctype_alnum 5 times slower in PHP 8.1 or greater
| From: | joanhey | Date: | Sat, 19 Aug 2023 12:29:21 +0000 |
| Subject: | [php-src] Issue #11997: ctype_alnum 5 times slower in PHP 8.1 or greater | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245207@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11997
Author: joanhey
### Description
The following code:
```php
<?php
$foo = '112312312312323';
$start_time = microtime(true);
for ($i = 0; $i < 10000; $i++) {
$foo = $foo.'1';
preg_match('/^[a-zA-Z0-9]+$/', $foo);
}
$end_time = microtime(true);
echo 'preg_match Result: ' . ($end_time - $start_time).PHP_EOL;
$foo = '112312312312323';
$start_time = microtime(true);
for ($i = 0; $i < 10000; $i++) {
$foo = $foo.'1';
ctype_alnum($foo);
}
$end_time = microtime(true);
echo 'ctype Result: ' . ($end_time - $start_time).PHP_EOL;
```
Resulted in this output:
A lot slower in 8.1 and 8.2
But I expected this output instead:
The same that in 8.0 or smaller.
Here start the performance degradation:

https://3v4l.org/fjSaZ
https://onlinephp.io/code/e3b9ddc370fdb0f00ff40447eadc24def0dd1abe
PD: I didn't test other ctype_* functions
### PHP Version
8.1
### Operating System
_No response_