Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
$count = 25000;
$functions = [
'carbon' => function ($i) {
return now()->subDays($i)->format('Y-m-d');
},
'strtotime' => function ($i) {
return date('Y-m-d', strtotime("$i days ago"));
},
'timestamps' => function ($i) {
return date('Y-m-d', time() - ($i * 24 * 60 * 60));
}
];
$results = [];
foreach ($functions as $key => $func) {
$time = microtime(true);
for ($i = 0; $i < $count; $i++) {
$date = $func($i);
echo $date . PHP_EOL;
}
$time = round(microtime(true) - $time, 6);
$results[$key] = $time;
}
foreach ($results as $key => $time) {
echo 'Parsed ' . number_format($count, 0, ',', '.') . " dates in $time seconds using $key.\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.