[php-src] PR #12431: Optimize strspn()
| From: | nielsdos | Date: | Fri, 13 Oct 2023 17:14:13 +0000 |
| Subject: | [php-src] PR #12431: Optimize strspn() | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-23879@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/12431
Author: nielsdos
The current implementation uses a nested loop (for + goto), which has complexity O(|s1| * |s2|). If
we instead use a lookup table, the complexity drops to O(|s1| + |s2|).
This is conceptually the same strategy that common C library implementations such as glibc and musl
use.
The variation with a bitvector instead of a table also gives a speed-up, but the table variation
(i.e. this one) was about 1.34x faster.
On microbenchmarks this easily gave a 5x speedup.
This can bring a 1.4-1.5% performance improvement in the Symfony benchmark.