count() optimization with !empty() check instead when possible #90
Conversation
samsonasik
commented
May 7, 2018
- Is this related to quality assurance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fine, we can also use casting too bool
:
return (bool) array_filter(...);
or:
return array_filter(...) ? true : false
not sure what is the most efficient... hah
Are there any benchmarks on these optimizations? Honestly, I find I guess I'm wondering if the optimizations will offer any measurable benefit that warrants reviewing, merging, and releasing these dozens of patches, particularly when there may be good rationale to leave the code as-is. Can you provide the background that led to these pull requests, please? |
there is online benchmark for it http://maettig.com/code/php/php-performance-benchmarks.php#empty |
That's VERY old: don't base yourself on it. If we want to go with benchmarks, we should use our own benchmarks: https://github.com/zendframework/zend-stdlib/tree/7c7663c7c580563a14ac03783a981452254d1052/benchmark |
Based on that link, @samsonasik, I'd argue that the approach that is more semantically close to what we want to demonstrate then is But as @Ocramius notes: we have a benchmark suite in this repo already. Add benchmarks so we can prove it. |
I've added the benchmark, this is on
cherry-picked to
|
@samsonasik Honestly, that demonstrates almost no measurable difference. I'd prefer we go with |
@weierophinney updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
Note: I'm merging the patch as-is, but the most effective performance optimisation here would be to loop and bail out early if a value is found. Would be interesting to have such functional construct in the library 👍 |