note 95564 added to function.date-default-timezone-set
| From: | ChristopherKramer at osu1 dot php dot net | Date: | Sat, 09 Jan 2010 15:52:21 +0000 |
| Subject: | note 95564 added to function.date-default-timezone-set | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164812@lists.php.net to get a copy of this message | ||
I experienced that using this function highly increases performance of functions like getdate() or
date() using PHP 5.2.6 on Windows.
I experienced similar results on Linux servers with PHP 5.2.6 and 5.2.10, although the difference
was not that significant on these servers: The PHP 5.2.10 server did run with
date_default_timezone_set ("only") twice as fast as without. The 5.2.6 server did 5 times
faster with date_default_timezone_set. As you can see below, the 5.2.6-Windows machine did a LOT
faster.
Of course these machines have completely different hardware and can not really be compared, but all
show improved performance.
I checked PHP 4.4.9 on Windows (without date_default_timezone_set of course) and noticed that its as
fast as PHP 5.2.6 with date_default_timezone_set.
The following script shows this:
<?php
# uncomment to see difference
# date_default_timezone_set(date_default_timezone_get());
function getmicrotime()
{
list($usec, $sec) = explode(' ',microtime());
return ($sec.substr($usec,1,7));
}
$start=mktime(0,0,0,1,1,2005);
$end=mktime(0,0,0,1,1,2020);
$nr=50000;
$start_time=getmicrotime();
for($i=0;$i<$nr;$i++) {
# $value=getdate(rand($start,$end));
date("H:i:s d.m.Y",rand($start,$end));
}
$end_time=getmicrotime();
echo "Time: ".($end_time-$start_time);
// With date_default_timezone_set(): "Time: 0.379343986511"
// Without date_default_timezone_set(): "Time: 7.4971370697"
?>
Note that the timezone is not changed, it is only set again. I really wonder why this makes such a
big performance difference, but its good to know.
----
Server IP: 69.147.83.197
Probable Submitter: 91.45.113.100
----
Manual Page -- http://www.php.net/manual/en/function.date-default-timezone-set.php
Edit -- https://master.php.net/note/edit/95564
Del: integrated -- https://master.php.net/note/delete/95564/integrated
Del: useless -- https://master.php.net/note/delete/95564/useless
Del: bad code -- https://master.php.net/note/delete/95564/bad+code
Del: spam -- https://master.php.net/note/delete/95564/spam
Del: non-english -- https://master.php.net/note/delete/95564/non-english
Del: in docs -- https://master.php.net/note/delete/95564/in+docs
Del: other reasons-- https://master.php.net/note/delete/95564
Reject -- https://master.php.net/note/reject/95564
Search -- https://master.php.net/manage/user-notes.php