If a calculation is used in the evaluation expression of an if
statement and then again in the execution statement(s), is it more or less efficient to perform the calculation twice or to introduce a new variable?
In other words, is
if ($x <> some_complex_calculation()) {
$x = some_complex_calculation();
}
better than this:
$result = some_complex_calculation();
if ($x <> $result) {
$x = $result;
}
Or, is this:
if ($x <> get_something_from_database()) {
$x = get_something_from_database();
}
better than this:
$result = get_something_from_database();
if ($x <> $result) {
$x = $result;
}
Aucun commentaire:
Enregistrer un commentaire