[php-src] Issue #8887: Performance: only sort if more than 1 element
| From: | kkmuffme | Date: | Tue, 28 Jun 2022 19:16:48 +0000 |
| Subject: | [php-src] Issue #8887: Performance: only sort if more than 1 element | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241828@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8887
Author: kkmuffme
### Description
All sort functions should use count() internally, to only sort when there is more than 1 element.
Currently using count and running sort conditionally is 100-200% faster on average.
```php
<?php
# faster
if ( count( $array ) > 1 ) {
sort( $array );
}
# slower:
sort( $array );
```
### PHP Version
PHP 8.1.7
### Operating System
Unix