Skip to content

Instantly share code, notes, and snippets.

@jerodev
Created July 9, 2019 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerodev/42c581e7301ac970313ac97d37647815 to your computer and use it in GitHub Desktop.
Save jerodev/42c581e7301ac970313ac97d37647815 to your computer and use it in GitHub Desktop.
<?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