Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <?php
  2.  
  3. $count = 25000;
  4. $functions = [
  5. 'carbon' => function ($i) {
  6. return now()->subDays($i)->format('Y-m-d');
  7. },
  8. 'strtotime' => function ($i) {
  9. return date('Y-m-d', strtotime("$i days ago"));
  10. },
  11. 'timestamps' => function ($i) {
  12. return date('Y-m-d', time() - ($i * 24 * 60 * 60));
  13. }
  14. ];
  15.  
  16. $results = [];
  17. foreach ($functions as $key => $func) {
  18.  
  19. $time = microtime(true);
  20.  
  21. for ($i = 0; $i < $count; $i++) {
  22. $date = $func($i);
  23. echo $date . PHP_EOL;
  24. }
  25.  
  26. $time = round(microtime(true) - $time, 6);
  27.  
  28. $results[$key] = $time;
  29. }
  30.  
  31. foreach ($results as $key => $time) {
  32. echo 'Parsed ' . number_format($count, 0, ',', '.') . " dates in $time seconds using $key.\n";
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement