Guest User

Untitled

a guest
Sep 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. <?php
  2.  
  3. class ScalarValue
  4. {
  5. /** @var string */
  6. protected $data;
  7. protected $channel;
  8. protected $locale;
  9. protected $attribute;
  10.  
  11. public function __construct(string $attribute, $channel, $locale, $data)
  12. {
  13. $this->attribute = $attribute;
  14. $this->channel = $channel;
  15. $this->locale = $locale;
  16. $this->data = $data;
  17. }
  18.  
  19. /**
  20. * * {@inheritdoc}
  21. * */
  22. public function __toString()
  23. {
  24. return (string) $this->data;
  25. }
  26.  
  27. public function attribute() {
  28. return $this->attribute;
  29. }
  30.  
  31. public function channel() {
  32. return $this->channel;
  33. }
  34.  
  35. public function locale() {
  36. return $this->locale;
  37. }
  38.  
  39. public function data() {
  40. return $this->data;
  41. }
  42. }
  43.  
  44. $content = '';
  45. $numberValues = array_merge(
  46. range(10, 1000, 10)
  47. range(10, 990, 10),
  48. range(1000, 2900, 100),
  49. range(3000, 10000, 1000)
  50. );
  51.  
  52. foreach ($numberValues as $numberValue) {
  53. printf("number values =%.4f\n", $numberValue);
  54. $ts = microtime(true);
  55. $value = new ScalarValue('attribute', 'channel', 'en_US', 'this is data');
  56. for($i=0;$i<100;$i++) {
  57. $result = [];
  58. for($j=0;$j<$numberValue;$j++) {
  59. $storageValue = [];
  60. $storageValue[$value->attribute() . $j][$value->channel()][$value->locale()] = $value->data();
  61.  
  62. $result = array_replace_recursive($result, $storageValue);
  63. }
  64. }
  65. $endMultipleMerge = microtime(true) - $ts;
  66. printf("array_replace_recursive for each value =%.4f\n", $endMultipleMerge);
  67.  
  68.  
  69. $ts = microtime(true);
  70. $value = new ScalarValue('attribute', 'channel', 'en_US', 'this is data');
  71. for($i=0;$i<100;$i++) {
  72. $normalizedValues = [];
  73. $result = [];
  74. for($j=0;$j<$numberValue;$j++) {
  75. $storageValue = [];
  76. $storageValue[$value->attribute() . $j][$value->channel()][$value->locale()] = $value->data();
  77.  
  78. $normalizedValues[] = $storageValue;
  79. }
  80.  
  81. $result = array_replace_recursive(...$normalizedValues);
  82. }
  83. $endSingleMerge = microtime(true) - $ts;
  84. printf("array_replace_recursive for all values =%.4f\n", $endSingleMerge);
  85.  
  86. $content .= sprintf('%s %s %s %s', $numberValue, $endMultipleMerge, $endSingleMerge, PHP_EOL);
  87. }
  88.  
  89. file_put_contents('./results.txt', $content);
Add Comment
Please, Sign In to add comment