note 25990 deleted from function.strtotime by sniper

From: Date: Tue, 21 Oct 2003 11:03:05 +0000
Subject: note 25990 deleted from function.strtotime by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-59016@lists.php.net to get a copy of this message
Note Submitter: one@groobo.com ---- 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.

« previous php.notes (#59016) next »