note 105561 deleted from language.constants by danbrown
| From: | danbrown@php.net | Date: | Mon, 29 Aug 2011 12:48:08 +0000 |
| Subject: | note 105561 deleted from language.constants by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182808@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
In reply to meint at meint dot net:
I had code like this:
$flag and $i++;
I bench tested it against this:
if ($flag) $i++;
in a loop of 10000 times.
I ran the test 20+ times.
It consistently yielded faster times to use "if" (I forget by how much, but enough to make
a difference to me). I suppose this is because there is one or two more steps of operations and of
throwing a value on the system stack (the final boolean combined value of ($flag and $i++)) using
"and", or something like that.
Somewheres else on this site I read how PHP was tuned to make "if" work as fast as
possible. Even though it must evaluate the opcode of "if", it must also evaluate and
execute the opcode "and", which may be farther down on the "list of opcodes" and
the "address table" for each opcode. In other words, it may work harder just to
understand that you mean "and" in the first place.
The first way sure does look nice though!