Formated Paste

  1. <?php
  2. if (isset($_SERVER['_']))
  3. echo shell_exec($_SERVER['_'] .' -v | head -n 1');
  4. else
  5. echo `php -v | head -n 1`;
  6. echo "\n";
  7.  
  8. $array_size = 1000;
  9. $array_data_size = 1000;
  10. $loops = 1000;
  11.  
  12. $data = array();
  13.  
  14. for ($i = 0; $i < $array_size; $i++)
  15. $data[] = str_repeat('a', $array_data_size);
  16.  
  17. $data_serialized = serialize($data);
  18. $data_json = json_encode($data);
  19.  
  20. echo 'Array Size: ' . $array_size . "\n";
  21. echo 'Data Size: ' . $array_data_size . "\n";
  22. echo 'Loops to run: ' . $array_data_size . "\n";
  23.  
  24. /******** SERIALIZE *************/
  25. echo "\nSerialize(): ";
  26. $start = microtime(true);
  27.  
  28. for ($i = 0; $i < $loops; $i++)
  29. serialize($data);
  30.  
  31. $stop = microtime(true);
  32. $diff = $stop - $start;
  33.  
  34. echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';
  35.  
  36.  
  37. /******** JSON *************/
  38. echo "\njson_encode(): ";
  39. $start = microtime(true);
  40.  
  41. for ($i = 0; $i < $loops; $i++)
  42. json_encode($data);
  43.  
  44. $stop = microtime(true);
  45. $diff = $stop - $start;
  46.  
  47. echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';
  48.  
  49.  
  50. /******** SERIALIZE DECODE *************/
  51. echo "\nunserialize(): ";
  52. $start = microtime(true);
  53.  
  54. for ($i = 0; $i < $loops; $i++)
  55. unserialize($data_serialized);
  56.  
  57. $stop = microtime(true);
  58. $diff = $stop - $start;
  59.  
  60. echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';
  61.  
  62.  
  63. /******** JSON DECODE *************/
  64. echo "\njson_decode(): ";
  65. $start = microtime(true);
  66.  
  67. for ($i = 0; $i < $loops; $i++)
  68. json_decode($data_json);
  69.  
  70. $stop = microtime(true);
  71. $diff = $stop - $start;
  72.  
  73. echo round($diff, 3) . ' (Start: ' . $stop . ' | Stop: ' . $start . ')';
  74.  
  75. echo "\n\n";
Name:
Email:
Code/text to paste:
  • Enable code highlighting
  • Code Language:
  • What software do we use to power the pastebin?: