I have a big set of loops for processing data and checked several SO topics to increase current performance of my code. Thanks to this question, I converted all my stdObjects
to array
and it already made a difference in terms of performance.
Then I figured out using ===
(is exactly equal to) is slightly faster than using ==
(is equal to). (source)
But I also believe that casting variable also requires some resource.
How could I understand if I manage to gain performance by casting a variable to use ===
instead of ==
?
Example code:
foreach ($bigDataSet as $key => $val) {
$key = (int)$key;
if ($key === $someInt) {
//do_some_work (other foreachs like above)
} elseif ($key === $someIntN) {
//do_some_work_n (other foreachs like above)
}
}
Current code:
foreach ($bigDataSet as $key => $val) {
if ($key == $someTypeWithINTVAL) {
//do_some_work (other foreachs like above)
} elseif ($key == $someTypeWithINTVALN) {
//do_some_work_n (other foreachs like above)
}
}
Thanks in advance for any guide regarding to this matter.