note 29116 deleted from control-structures.switch by victor
| From: | victor@php.net | Date: | Mon, 03 Feb 2003 12:37:23 +0000 |
| Subject: | note 29116 deleted from control-structures.switch by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43323@lists.php.net to get a copy of this message | ||
I did some performance testing comparing a series of if/elseif statements against the switch
statement. The system was a Pentium II 266 running the ISAPI version of PHP 4.3 on IIS. This was the
code:
for ($i = 0; $i < 10000; $i++) {
if ($bla == 1) { $bla = 2;
} elseif ($bla == 2) { $bla = 3;
} elseif ($bla == 3) { $bla = 4;
} elseif ($bla == 4) { $bla = 1;
} else { $bla = 1;
}
}
for ($i = 0; $i < 10000; $i++) {
switch ($bla) {
case 1: $bla = 2; break;
case 2: $bla = 3; break;
case 3: $bla = 4; break;
case 4: $bla = 1; break;
default: $bla = 1;
}
}
if/elseif took an average of 0.085 seconds.
switch took an average of 0.097 seconds.