Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ScalarValue
- {
- /** @var string */
- protected $data;
- protected $channel;
- protected $locale;
- protected $attribute;
- public function __construct(string $attribute, $channel, $locale, $data)
- {
- $this->attribute = $attribute;
- $this->channel = $channel;
- $this->locale = $locale;
- $this->data = $data;
- }
- /**
- * * {@inheritdoc}
- * */
- public function __toString()
- {
- return (string) $this->data;
- }
- public function attribute() {
- return $this->attribute;
- }
- public function channel() {
- return $this->channel;
- }
- public function locale() {
- return $this->locale;
- }
- public function data() {
- return $this->data;
- }
- }
- $content = '';
- $numberValues = array_merge(
- range(10, 1000, 10)
- range(10, 990, 10),
- range(1000, 2900, 100),
- range(3000, 10000, 1000)
- );
- foreach ($numberValues as $numberValue) {
- printf("number values =%.4f\n", $numberValue);
- $ts = microtime(true);
- $value = new ScalarValue('attribute', 'channel', 'en_US', 'this is data');
- for($i=0;$i<100;$i++) {
- $result = [];
- for($j=0;$j<$numberValue;$j++) {
- $storageValue = [];
- $storageValue[$value->attribute() . $j][$value->channel()][$value->locale()] = $value->data();
- $result = array_replace_recursive($result, $storageValue);
- }
- }
- $endMultipleMerge = microtime(true) - $ts;
- printf("array_replace_recursive for each value =%.4f\n", $endMultipleMerge);
- $ts = microtime(true);
- $value = new ScalarValue('attribute', 'channel', 'en_US', 'this is data');
- for($i=0;$i<100;$i++) {
- $normalizedValues = [];
- $result = [];
- for($j=0;$j<$numberValue;$j++) {
- $storageValue = [];
- $storageValue[$value->attribute() . $j][$value->channel()][$value->locale()] = $value->data();
- $normalizedValues[] = $storageValue;
- }
- $result = array_replace_recursive(...$normalizedValues);
- }
- $endSingleMerge = microtime(true) - $ts;
- printf("array_replace_recursive for all values =%.4f\n", $endSingleMerge);
- $content .= sprintf('%s %s %s %s', $numberValue, $endMultipleMerge, $endSingleMerge, PHP_EOL);
- }
- file_put_contents('./results.txt', $content);
Add Comment
Please, Sign In to add comment