|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-26 13:16 UTC] dor at videocells dot com
Description:
------------
Hi, it seems to me that the DateTimeZone::getTransitions() function suffered a performance loss of some degree between php 5.2.9 and 5.3
each call to it takes about one tenth of a second.
I noticed this because I happen to have a function that recieves many timezones and checks the transistions of each of them.
Recently I discovered a performance loss on my web gui, and after some research i found out that for some reason the getTransitions() function takes a noticable amount of time to run. much
more than with php 5.2.9 for the same request to complete.
note that since we worked with previous versions of php, it is called without the new parameters added in php 5.3
Reproduce code:
---------------
$TimezonesToAdd = array (
"(GMT -12:00) International Date Line West" => "Etc/GMT+12", "(GMT -11:00) Midway Island, Samoa" => "Pacific/Midway",
"(GMT -10:00) Hawaii" => "US/Hawaii",
// many many more time zones...
"(GMT +12:00) Auckland, Wellington" => "Pacific/Auckland",
"(GMT +12:00) Fiji, Kamchatka, Marshall Is." => "Asia/Kamchatka",
"(GMT +13:00) Nuku'alofa" => "Pacific/Tongatapu");
foreach ($TimezonesToAdd as $TimezoneDescription => $TimezoneID)
{
EnsureTimezoneExists ($TimezoneID);
self::$_AvailableTimezones [$TimezoneID] = $TimezoneDescription;
}
function EnsureTimezoneExists($TimezoneID)
{
$res = timezone_open($TimezoneID)
if($res)
{
$TimeInTimezone = new DateTime ("now",$res)
//the following line takes alot of time :
$trans = $res->getTransitions();
}
}
Expected result:
----------------
The $res->getTransitions() call should cost in the magnitude of 0.001 seconds, but instead it takes about 0.1 seconds, which is noticable.
Actual result:
--------------
microtime() calls before and after the function call, show that the function takes about 0.1 seconds to run
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
<?php $timezoneArray = array ( "(GMT -12:00) International Date Line West" => "Etc/GMT+12", "(GMT -11:00) Midway Island, Samoa" => "Pacific/Midway", "(GMT -10:00) Hawaii" => "US/Hawaii", // many many more time zones... "(GMT +12:00) Auckland, Wellington" => "Pacific/Auckland", "(GMT +12:00) Fiji, Kamchatka, Marshall Is." => "Asia/Kamchatka", "(GMT +13:00) Nuku'alofa" => "Pacific/Tongatapu"); foreach ($timezoneArray as $TimezoneDescription => $TimezoneID) { $res = timezone_open($TimezoneID) if($res) { $TimeInTimezone = new DateTime ("now",$res) $microParts = explode(" ",microtime()); list($a,$b) = explode(".",$microParts[0]); echo "before : ".strftime('%Y%m%d-%H%M%S',time()).".".$b; //the following line takes alot of time : $trans = $res->getTransitions(); $microParts_2 = explode(" ",microtime()); list($c,$d) = explode(".",$microParts_2[0]); echo "before : ".strftime('%Y%m%d-%H%M%S',time()).".".$d; } }With this simplified and working (!) script I get exactly same results with PHP_5_2, PHP_5_3 and HEAD of today: <?php $timezoneArray = array ( "(GMT -12:00) International Date Line West" => "Etc/GMT+12", "(GMT -11:00) Midway Island, Samoa" => "Pacific/Midway", "(GMT -10:00) Hawaii" => "US/Hawaii", // many many more time zones... "(GMT +12:00) Auckland, Wellington" => "Pacific/Auckland", "(GMT +12:00) Fiji, Kamchatka, Marshall Is." => "Asia/Kamchatka", "(GMT +13:00) Nuku'alofa" => "Pacific/Tongatapu"); foreach ($timezoneArray as $TimezoneDescription => $TimezoneID) { $res = timezone_open($TimezoneID); if($res) { $start = microtime(true); $trans = $res->getTransitions(); $end = microtime(true); var_dump(1000 * ($end - $start)); } } ?> Now, where is the performance issue here?