3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DataMapper { /** * @var array */ private $rawData; /** * @var array */ private $parsedData; /** * @var array */ private $mapping = [ 'dbField1' => 'outputField1', 'dbField2' => ['outputField3' => ['double']] 'dbField3' => ['outputField3' => ['double', 'dollars']] ]; public function __construct(array $data) { $this->rawData = $data; $this->mapData(); } /** * @param $value * @return mixed */ private function double($value) { return $value * 2; } /** * @param $value * @return string */ private function dollars($value) { return $value . "$"; } // Yes, I know the methods shouldn't be here but it rather be decoupled in another class and // injected with a DI it but I wrote it like this with example purposes only private function mapData() { foreach($this->mapping as $dbFieldName => $content) { if(isset($this->rawData[$dbFieldName])) { if(is_string($content)) { $this->parsedData[$content] = $this->rawData[$dbFieldName]; } else if (is_array($content)) { $frontFieldName = key($content); $functionsArray = reset($content); $value = $this->rawData[$dbFieldName]; foreach($functionsArray as $functionName) { $value = $this->{$functionName}($value); } $this->parsedData[$frontFieldName] = $value; } } } } /** * Simple getter * @return array */ public function getParsedData() { return $this->parsedData; } } // Usually the data comes from the DB so it would be in some kind of Row Set structure $data = ['dbField1' => 1, 'dbField2' => 10, 'dbField3' => 100]; // The data is handed to the Holder which parses it $dm = new DataMapper($data); // The data is parsed so it can be echo json_encode($dm->getParsedData());

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.320.0040.03812.51
5.4.310.0070.03612.50
5.4.300.0070.03412.52
5.4.290.0030.04012.50
5.4.280.0100.03012.40
5.4.270.0050.03512.41
5.4.260.0050.03712.40
5.4.250.0070.03912.40
5.4.240.0030.03712.41
5.4.230.0090.04012.40
5.4.220.0050.03612.39
5.4.210.0030.03612.40
5.4.200.0040.03712.39
5.4.190.0060.03412.39
5.4.180.0070.03312.39
5.4.170.0040.03612.40
5.4.160.0050.03512.39
5.4.150.0040.03812.39
5.4.140.0080.03912.08
5.4.130.0040.03712.07
5.4.120.0070.03812.04
5.4.110.0120.03312.02
5.4.100.0060.03412.03
5.4.90.0060.04312.03
5.4.80.0060.04112.03
5.4.70.0030.03712.02
5.4.60.0080.03912.02
5.4.50.0050.03412.02
5.4.40.0090.03112.01
5.4.30.0060.04212.01
5.4.20.0040.03712.00
5.4.10.0060.03812.00
5.4.00.0070.03511.50
5.3.290.0080.04512.80
5.3.280.0110.03712.71
5.3.270.0080.03812.72
5.3.260.0070.04312.72
5.3.250.0070.03512.72
5.3.240.0080.03412.72
5.3.230.0050.03812.71
5.3.220.0050.03712.68
5.3.210.0060.04612.68
5.3.200.0070.03512.68
5.3.190.0050.03812.68
5.3.180.0040.03812.67
5.3.170.0080.03312.67
5.3.160.0110.03712.67
5.3.150.0060.04112.68
5.3.140.0100.03512.66
5.3.130.0090.03412.66
5.3.120.0060.03812.66
5.3.110.0080.03612.66
5.3.100.0030.04012.12
5.3.90.0090.03212.10
5.3.80.0060.04412.09
5.3.70.0070.03312.09
5.3.60.0080.03312.07
5.3.50.0050.03612.02
5.3.40.0050.03612.04
5.3.30.0050.03411.98
5.3.20.0040.03511.76
5.3.10.0070.03111.73
5.3.00.0080.03311.71
5.2.170.0040.0329.23
5.2.160.0040.0289.22
5.2.150.0040.0309.22
5.2.140.0050.0299.21
5.2.130.0070.0269.18
5.2.120.0060.0269.18
5.2.110.0040.0379.18
5.2.100.0090.0239.17
5.2.90.0050.0289.18
5.2.80.0090.0319.17
5.2.70.0030.0379.17
5.2.60.0070.0309.13
5.2.50.0030.0309.10
5.2.40.0060.0359.07
5.2.30.0070.0269.04
5.2.20.0030.0329.03
5.2.10.0030.0318.94
5.2.00.0060.0268.80
5.1.60.0030.0248.09
5.1.50.0060.0228.09
5.1.40.0040.0238.06
5.1.30.0030.0268.41
5.1.20.0050.0248.44
5.1.10.0070.0258.17
5.1.00.0050.0238.16
5.0.50.0050.0186.64
5.0.40.0040.0186.50
5.0.30.0030.0316.32
5.0.20.0030.0196.28
5.0.10.0050.0176.26
5.0.00.0020.0326.25
4.4.90.0030.0154.78
4.4.80.0030.0154.76
4.4.70.0030.0154.75
4.4.60.0030.0204.76
4.4.50.0030.0184.77
4.4.40.0020.0254.71
4.4.30.0040.0214.76
4.4.20.0050.0134.84
4.4.10.0030.0144.85
4.4.00.0050.0244.76
4.3.110.0020.0194.67
4.3.100.0020.0154.66
4.3.90.0050.0124.63
4.3.80.0040.0224.58
4.3.70.0050.0114.63
4.3.60.0010.0154.63
4.3.50.0030.0144.63
4.3.40.0040.0224.53
4.3.30.0020.0163.30
4.3.20.0030.0163.28
4.3.10.0040.0193.23
4.3.00.0400.0136.07

preferences:
140.55 ms | 1394 KiB | 7 Q