In PHP switch
statements, does placing more common cases near the top improve performance?
For example, say the following function is called 1,000 times:
<?php
function foo_user ($op) {
switch ($op) {
case 'after_update':
//Some Stuff
case 'login':
//Some other Stuff
}
}
If in 990 of the 1,000 of the times the function is called the $op argument is 'login', would performance improve by having case: 'login'
above case 'after_update':
in the switch
statement? For example, would the code after case 'after_update':
be ignored if $op = login
was passed?
I've run some informal tests on this idea, but the difference has been negligible -- perhaps because the code after case: 'login'
and case 'after_update':
are both trivial. I'd prefer to avoid setting up a more extensive test with non-trivial operations if someone knows the answer outright.
This is specifically a Drupal question, but I imagine it could be addressed by anyone who is familiar with optimizing PHP.