Last active
August 29, 2015 14:17
-
-
Save gaborwho/adcfb59ccc1c9dd97848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cycles = pow(10, 5); | |
echo "Execution times for $cycles iterations:" . PHP_EOL; | |
$code = '$newDate = clone $date;'; | |
measure($cycles, $code); | |
$code = '$newDate = new DateTime($timestamp, $timezone);'; | |
measure($cycles, $code); | |
function measure($cycles, $code) | |
{ | |
echo $code . PHP_EOL; | |
$startClone = microtime(true); | |
$date = new DateTime('now', new DateTimeZone('Europe/Budapest')); | |
$timestamp = '@' . $date->format('U'); | |
$timezone = $date->getTimezone(); | |
for ($i = 0; $i < $cycles; $i++) | |
{ | |
eval($code); | |
} | |
echo microtime(true) - $startClone . PHP_EOL; | |
} |
Author
gaborwho
commented
Mar 24, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment