/ Published in: PHP
Here is the research of running the scripts 10000 times, in milliseconds:
preg_match('/.*\.(jpg|gif|png)\z/',substr('the image/is on/fire.jpg,-4'))
0.29-0.27
in_array(strtolower(substr('the image/is on/fire.jpg',-3)), array('jpg','gif','png'))
0.03-0.025
switch (strtolower(substr('the image/is on/fire.jpg',-3))){
case 'jpg':
case 'gif':
case 'png':
$ec = true;
}//use $ec for return statement
0.019-0.14
preg_match('/.*\.(jpg|gif|png)\z/',substr('the image/is on/fire.jpg,-4'))
0.29-0.27
in_array(strtolower(substr('the image/is on/fire.jpg',-3)), array('jpg','gif','png'))
0.03-0.025
switch (strtolower(substr('the image/is on/fire.jpg',-3))){
case 'jpg':
case 'gif':
case 'png':
$ec = true;
}//use $ec for return statement
0.019-0.14