Bug #63699 [NEW]: Poor date()/etc performance [PATCH]
From: njaguar at gmail dot com
Operating system: *
PHP version: 5.4.9
Package: Performance problem
Bug Type: Bug
Bug description:Poor date()/etc performance [PATCH]
Description:
------------
More info: http://news.php.net/php.internals/64147
I ended up digging deeper and created a patch for this.
Summary of changes:
- Created a new tz_checked_valid flag on the global date structure
- Created a callback method when date.timezone is modified by the ini
(set)
- Callback checks validity if set during runtime, and will error (with line
number) accordingly. This is probably useful for some users that might no
otherwise have realized they made a mistake on their ini_set() line in
their code.
- In guess_timezone(), if tz_checked_valid is not set, attempts to
validate, errors if cannot.
As previously noted from my benchmarks, over 1 million runs, it increased
performance from:
date : 1.751 sec
strftime : 1.872 sec
strtotime : 3.195 sec
to:
date : 1.238 sec
strftime : 0.999 sec
strtotime : 2.337 sec
Here is a test case to show that it will not blow up on invalid timezones,
and revalidates accordingly:
<?php
ini_set('date.timezone', 'FAKE_TIMEZONE');
echo date('F j, Y, g:i a');
ini_set('date.timezone', 'America/Chicago');
echo date('F j, Y, g:i a');
?>
Note: If the ini is actually set wrong, it will not error until they call a
date function that makes use of the timezone, just like before.
Thanks!
Test script:
---------------
$c = 1000000;
for($i=0; $i<$c; $i++) date('F j, Y, g:i a');
etc..
Expected result:
----------------
Performance results are benchmarked and displayed in the general
description
Actual result:
--------------
Performance results are benchmarked and displayed in the general
description
--
Edit bug report at https://bugs.php.net/bug.php?id=63699&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63699&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63699&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63699&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=63699&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=63699&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=63699&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=63699&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=63699&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=63699&r=support
Expected behavior: https://bugs.php.net/fix.php?id=63699&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=63699&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=63699&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=63699&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63699&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=63699&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=63699&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=63699&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63699&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=63699&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=63699&r=mysqlcfg
Thread (3 messages)
- njaguar at gmail dot com