SHARE
TWEET

Untitled

a guest Jul 20th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top