|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-07-01 20:55 UTC] jerico dot dev at gmail dot com
Description:
------------
strtotime() performs 3 orders of magnitude slower when operating on a timestamp.
Reproduce code:
---------------
$string = '1902-03-25 18:25:25';
$timestamp = strtotime($string);
$mt0 = microtime(true);
$result1 = strtotime("$string +1 year");
$mt1 = microtime(true);
$result2 = strtotime("+1 year", $timestamp);
$mt2 = microtime(true);
printf("%.6f\r\n%.6f\r\n", $mt1-$mt0, $mt2-$mt1);
// This will output
// 0.000171
// 0.721877
// on my machine
Actual result:
--------------
see reproduce code
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 07:00:01 2025 UTC |
I'll have a look at this, but there is even a MUCH faster way: <?php $d = new DateTime( '1902-03-25 18:25:25' ); $mt0 = microtime(true); $d->modify( '+1 year' ); $mt1 = microtime(true); $d->modify( '+1 year' ); $mt2 = microtime(true); printf("%.6f\r\n%.6f\r\n", $mt1-$mt0, $mt2-$mt1); ?> 0.013312/0.696215 for your code, vs 0.000065/0.000028 for my approach.