true. i will thing about it.. it makes no sense, if test runs more than 30 seconds. that means CPU is slow…
I have added failover code – if any benchmark runs more than 20seconds – it will stop and avoid PHP crash. Please update to latest version.
I debugged the code and it’s last $paragraphed
$paragraphed = preg_replace('/\n\n(.+?)(?=\n\n|\z)/s', "<p>\\1</p>", $paragraphed);
This test on my local runs in about 220 Β΅s, but on shared hosting, the same I posted results, is 2ms, 10x slower for some reason. Now, I think having limit you has added is great, but then we don’t have measurement. I suggest split regex test into two, simple and complex, move this problematic into the new test and make less cycles for it so it’s never more tan 2-3 seconds. Thank you!
you can not imagine, how in fact modern CPUs are. That’s why some tests have many cycles. Because otherwise it is so hard to measure spent time. π
If it runs fast on your local setup – that is good. There must be a reason, why it runs 10x times slower on shared hosting and that was the purpose for this plugin – to identify it. That means – shared hosting provider either has slow CPU or throttles your PHP scripts. This plugin idea was not to run fast, but to run heavy code to see – how much you can get out of your hosting. π
I’ve dived into this issue and I got the root cause. The slow regex is caused by disabled PCRE JIT. Once you change in php.ini pcre.jit=1 or ini_set(‘pcre.jit’,’1′); in wp-config.php, it would be up to 10x faster. For some reasons, shared hostings using Cloudlinux and Litespeed has this setting off by default.
I tested it in the real world scenario, how much improvement it would bring and the result is: negligible
A site using translation plugin Translatepress that is heavily using regex shown no sign of improvement in TTFB.
Now, I’m very grateful that your plugin could detect it and I will everywhere turn this setting on.
Thanks for sharing, very interesting. I will check my settings (we’re alos using cloudlinux, but don’t use CL PHP). I will also add your findings to suggestions on the page.
You welcome! BTW here is the test, if you set 0 in ini_set, the total time will be much slower
https://onlinephp.io/c/bd146
Thank you for your work!