note 25990 added to function.strtotime
| From: | one at groobo dot com | Date: | Mon, 14 Oct 2002 18:31:04 +0000 |
| Subject: | note 25990 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38061@lists.php.net to get a copy of this message | ||
I was actually wondering about the strtotime performance. It is, in fact a handy and powerful
function (it even understands strtotime('last month');).
My initial though was, using explode>mktime method, (especially in situations, when i exactly
know what date format i have on input (eg YYYY-mm-dd)) i will get results quicker.
Made some quick benchmarks, between two loops (postdate array holds 50,000 random dates):
// 1. strtotime method
for ($i=0; $i<sizeof($postdate); $i++) {
$ts[$i] = strtotime($postdate[$i]);
}
// 2. explode, mktime method
for ($i=0; $i<sizeof($postdate); $i++) {
list ($y,$m,$d) = explode('-', $postdate[$i]);
$ts[$i] = mktime(0,0,0,$m,$d,$y);
}
I was suprised to see the results, strtotime() was quicker - 1.25 s
vs explode > mktime - 2.20 s.
--
http://www.php.net/manual/en/function.strtotime.php
http://master.php.net/manage/user-notes.php?action=edit+25990
http://master.php.net/manage/user-notes.php?action=delete+25990
http://master.php.net/manage/user-notes.php?action=reject+25990