[performance] === much faster than & and == and other interesting performance stats
| From: | André Langhorst | Date: | Wed, 07 Jun 2000 17:31:17 +0000 |
| Subject: | [performance] === much faster than & and == and other interesting performance stats | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-20484@lists.php.net to get a copy of this message | ||
1.)
I´ve done some performance tests comparing & and == and the result is that & is about 25% faster than ==,
it´s really only 0,6*10^(-6)s faster and I think it won´t have a measureable effect on my scripts if I use & from now on...
After that I was interested if === is perhpas a bit faster than the other comparision operators and i found out that === is *a lot faster* than & and ==, it´s about 60% faster than == , I think that´s quite a measureable value,
perhaps it should be documented that if the phpuser is sure that he´ll compare two variables he expects to be of equal type and he´s going to compare a lot of variables, he should (could) use === instead of == or &
In fact it makes sense, no need for type conversions on two variables should speed === up against ==....
Just to complete this post, strcmp() seems to be a bit slower (<10%) than == and strcasecmp() is about 1,5 times slower than strcmp()
2.) Another test a)"if ($var)" against b)"if($var==TRUE)" against c)"if (isset($var))"
I remembered that some people don´t write "if ($var)" if they want to check if a variable is set (and != 0), they write "if($var==TRUE)", I don´t know if that´s popular, but I can´t advise anyone to use the longer version.
(b) is about 9 times slower than (a), I did not expect this to be so much... I could not measure if (a) or (c) is faster, the results were close to each other, although they have a bit different meaning.
3.) Finally in rush saving nanoseconds, I´ve tested the ternary operator ($c?TRUE:FALSE) against an if/else snipplet (if ($c) TRUE; else FALSE;),
I could not find out that the ternary operator is faster, I think it´s a bit slower... but it weights that it´s more elegant in my opinion.
greetings,
andré
tested on: php4 release - optimizer beta4