Micro-optimization of IF statement
I always look into how to optimize the code more and more every day, and
how I can learn to code faster code.
Looking at some minified JS online I notice the change of a few IF into a
statement and I thought that it might be a very good idea to start using
it in PHP as well.
<?php
if(!isset($myVar) || $myVar == 'val'){
$myVar = 'oldVal';
}
if(isset($myVar) && $myVar == 'oldVal'){
$myVar = 'newVal';
}
?>
into
<?php
(!isset($myVar) || $myVar == 'val') && $myVar = 'oldVal';
isset($myVar) && $myVar == 'oldVal' && $myVar = 'newVal';
?>
As I like the new syntax, I started to use it more and more thinking to
save processing time, but do I really save any or there is no difference
internally between the two ?
(The example code is just an EXAMPLE to only show the technique)
No comments:
Post a Comment