I use !empty() very often and decided to make a benchmark test.
Here is the code and results: http://pastebin.com/fMhhdQiW
if (!empty(...)) working on 23% slower than if (empty()) expression.
So if create new operator not_empty() it will improve performance.
The first question is: What do you think about optimizing !empty(...), do
we need it ?
And I see two way to make this happen.
- Create new language entity "not_empty".
- Improve parser and help to handle "!empty" calls different way.
It is obviously that option 2 is better. Is it real to optimize parser that
way?
Thanks!
--
Best Regards,
Oleg
Oleg Serov wrote:
I use !empty() very often and decided to make a benchmark test.
Here is the code and results: http://pastebin.com/fMhhdQiW
if (!empty(...)) working on 23% slower than if (empty()) expression.
So if create new operator not_empty() it will improve performance.
The first question is: What do you think about optimizing !empty(...), do
we need it ?And I see two way to make this happen.
- Create new language entity "not_empty".
- Improve parser and help to handle "!empty" calls different way.
It is obviously that option 2 is better. Is it real to optimize parser that
way?
I see a third way: optimize this on the OPcode level, i.e. BOOL_NOT(X) +
JMPZ(T) -> NOP, JMPNZ(X). That is already done by OPcache[1].
[1] http://lxr.php.net/xref/PHP_5_5/ext/opcache/Optimizer/block_pass.c#816
--
Christoph M. Becker
Thanks, with enabled opcache works fine.
Oleg Serov wrote:
I use !empty() very often and decided to make a benchmark test.
Here is the code and results: http://pastebin.com/fMhhdQiW
if (!empty(...)) working on 23% slower than if (empty()) expression.
So if create new operator not_empty() it will improve performance.
The first question is: What do you think about optimizing !empty(...), do
we need it ?And I see two way to make this happen.
- Create new language entity "not_empty".
- Improve parser and help to handle "!empty" calls different way.
It is obviously that option 2 is better. Is it real to optimize parser
that
way?I see a third way: optimize this on the OPcode level, i.e. BOOL_NOT(X) +
JMPZ(T) -> NOP, JMPNZ(X). That is already done by OPcache[1].[1] <
http://lxr.php.net/xref/PHP_5_5/ext/opcache/Optimizer/block_pass.c#816>--
Christoph M. Becker
--
Best Regards,
Oleg