Хорошо, я протестировал 4 разных метода:
function _strtotime($date) {
return strtotime($date);
}
function _preg($date) {
preg_match("@^(\\d+)-(\\d\\d)-(\\d\\d)$@", $date, $matches);
return mktime(0, 0, 0, $matches[2], $matches[3], $matches[1]);
}
function _explode($date) {
list($y,$m,$d) = explode("-", $date);
return mktime(0, 0, 0, $m, $d, $y);
}
function _substr($date) {
$y = substr($date, 0, 4);
$m = substr($date, 5, 2);
$d = substr($date, 8);
return mktime(0, 0, 0, $m, $d, $y);
}
// I also added this one as sort of a "control"
function _hardCoded() {
return mktime(0, 0, 0, 3, 31, 2009);
}
А вот результаты выполнения каждой функции 100 000 раз. С вводом «2009-03-31»
_hardCoded: 2.02547
_strtotime: 2.35341
_preg: 2.70448
_explode: 2.31173
_substr: 2.27883