I'm curious if anyone out there has found any good, reliable ways to benchmark various PHP functions. At the moment, I'm looking at trying to compare two or three ways of achieving the same result, and I have no idea how to properly benchmark the two methods to see which is faster, more efficient and more reliable.
For those curious, I am working with data that will always be in the form of a string. That string will always begin with two letters (either "ff" or "fs"), followed by any number of digits. I have considered the following possibilities, but I have no idea which method would be the most efficient, or if it would even make a difference.
I have looked at:
PHP Code:
$val = 'ff27'; # An example of what my val might look like
if(strstr($val,'ff') !== false) {
$id = substr($val,2,strlen($val)-2);
# Perform my code related to the ff value
}
elseif(strstr($val,'fs') !== false) {
$id = substr($val,2,strlen($val)-2);
# Perform my code related to the fs value
}
PHP Code:
$val = 'ff27'; # An example of what my val might look like
if(strstr($val,'ff') !== false) {
$id = str_replace('ff','',$val);
# Perform my code related to the ff value
}
elseif(strstr($val,'fs') !== false) {
$id = str_replace('fs','',$val);
# Perform my code related to the fs value
}
PHP Code:
$val = 'ff|27';
list($pre,$id) = explode('|',$val);
if($pre == 'ff') {
# Perform my code related to the ff value
}
elseif($pre == 'fs') {
# Perform my code related to the fs value
}
Anyone having any thoughts about the efficiency of any of these methods would be greatly appreciated.
In addition, if anyone has any good resources for comparing PHP code to check its efficiency (preferably a free method of doing so) would also be greatly appreciated. Thank you.