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' => ['outputField2' => ['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 but I wrote it like this just as an example 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' => 1, 'dbField3' => 1]; // 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)
8.3.60.0110.01118.43
8.3.50.0110.00921.21
8.3.40.0120.00318.79
8.3.30.0120.00319.10
8.3.20.0060.00320.33
8.3.10.0060.00320.52
8.3.00.0080.00019.50
8.2.180.0150.00016.88
8.2.170.0180.00322.96
8.2.160.0060.00920.47
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0090.00621.04
8.2.110.0060.00320.26
8.2.100.0080.00317.85
8.2.90.0090.00018.34
8.2.80.0040.00417.97
8.2.70.0050.00317.60
8.2.60.0000.00818.03
8.2.50.0060.00318.07
8.2.40.0000.00718.16
8.2.30.0040.00418.14
8.2.20.0030.00517.66
8.2.10.0000.00818.00
8.2.00.0030.00517.68
8.1.280.0060.01225.92
8.1.270.0050.00323.96
8.1.260.0080.00026.35
8.1.250.0060.00328.09
8.1.240.0030.00622.02
8.1.230.0000.01120.90
8.1.220.0040.00417.74
8.1.210.0060.00318.89
8.1.200.0030.00617.25
8.1.190.0060.00317.35
8.1.180.0050.00318.10
8.1.170.0000.00818.46
8.1.160.0000.00722.02
8.1.150.0070.00018.89
8.1.140.0030.00517.50
8.1.130.0070.00017.75
8.1.120.0040.00417.45
8.1.110.0040.00417.52
8.1.100.0060.00317.43
8.1.90.0030.00317.52
8.1.80.0040.00417.42
8.1.70.0000.00717.43
8.1.60.0080.00417.49
8.1.50.0030.00617.55
8.1.40.0080.00017.42
8.1.30.0000.00817.59
8.1.20.0000.00717.65
8.1.10.0040.00417.57
8.1.00.0000.00717.38
8.0.300.0040.00420.17
8.0.290.0000.00716.75
8.0.280.0030.00318.46
8.0.270.0030.00316.73
8.0.260.0030.00317.33
8.0.250.0050.00316.86
8.0.240.0070.00016.86
8.0.230.0070.00016.96
8.0.220.0000.00716.80
8.0.210.0000.00716.81
8.0.200.0040.00416.94
8.0.190.0090.00016.84
8.0.180.0030.00516.80
8.0.170.0000.00816.95
8.0.160.0030.00316.94
8.0.150.0000.00716.74
8.0.140.0000.00716.77
8.0.130.0090.00013.38
8.0.120.0050.00316.91
8.0.110.0040.00416.91
8.0.100.0030.00516.79
8.0.90.0000.00716.80
8.0.80.0120.00316.83
8.0.70.0000.00816.73
8.0.60.0040.00416.93
8.0.50.0060.00316.73
8.0.30.0130.00817.02
8.0.20.0040.01617.40
8.0.10.0040.00416.82
8.0.00.0110.01216.93
7.4.330.0000.00615.18
7.4.320.0000.00616.42
7.4.300.0000.00716.48
7.4.290.0030.00316.63
7.4.280.0040.00416.60
7.4.270.0000.00716.59
7.4.260.0000.00716.55
7.4.250.0080.00016.38
7.4.240.0060.00116.57
7.4.230.0050.00316.32
7.4.220.0120.00616.54
7.4.210.0030.01316.61
7.4.200.0040.00416.65
7.4.160.0110.00316.47
7.4.150.0180.00017.40
7.4.140.0090.00817.86
7.4.130.0070.01116.48
7.4.120.0050.01216.52
7.4.110.0140.01016.36
7.4.100.0120.00616.53
7.4.90.0170.00716.60
7.4.80.0030.01319.39
7.4.70.0190.00316.50
7.4.60.0070.01116.57
7.4.50.0030.00316.54
7.4.40.0120.00316.43
7.4.30.0030.02116.59
7.4.00.0100.00314.87
7.3.330.0050.00013.40
7.3.320.0060.00013.38
7.3.310.0030.00616.33
7.3.300.0030.00316.31
7.3.290.0080.00816.31
7.3.280.0090.01116.38
7.3.270.0130.00617.40
7.3.260.0090.00916.69
7.3.250.0110.00616.51
7.3.240.0050.01116.47
7.3.230.0060.00916.39
7.3.210.0070.01016.29
7.3.200.0070.01019.39
7.3.190.0110.00716.50
7.3.180.0120.00316.56
7.3.170.0030.01416.52
7.3.160.0120.00316.61
7.3.120.0000.01615.02
7.3.110.0060.00914.84
7.3.100.0120.00314.86
7.3.90.0120.00014.77
7.3.80.0080.00315.02
7.3.70.0090.00614.86
7.3.60.0000.01014.72
7.3.50.0040.00815.04
7.3.40.0070.00314.97
7.3.30.0060.00614.96
7.3.20.0030.00916.86
7.3.10.0000.01716.69
7.3.00.0060.00616.77
7.2.330.0150.00316.40
7.2.320.0120.01216.80
7.2.310.0040.01316.46
7.2.300.0000.01616.58
7.2.290.0070.01116.62
7.2.240.0000.01415.04
7.2.230.0000.01415.06
7.2.220.0080.00815.15
7.2.210.0030.01015.02
7.2.200.0080.00815.00
7.2.190.0030.01015.11
7.2.180.0040.01114.89
7.2.170.0070.01015.13
7.2.160.0060.00615.06
7.2.150.0060.01016.71
7.2.140.0030.01016.98
7.2.130.0090.00917.09
7.2.120.0080.00817.11
7.2.110.0040.00816.97
7.2.100.0030.01416.85
7.2.90.0070.00717.05
7.2.80.0060.00816.97
7.2.70.0090.00617.13
7.2.60.0080.00716.91
7.2.50.0070.00417.07
7.2.40.0100.00716.85
7.2.30.0000.01716.91
7.2.20.0080.00416.70
7.2.10.0030.01417.01
7.2.00.0040.00818.23
7.1.330.0060.01015.88
7.1.320.0060.00916.07
7.1.310.0000.01715.78
7.1.300.0070.00715.67
7.1.290.0110.00415.80
7.1.280.0150.00015.95
7.1.270.0070.00715.84
7.1.260.0030.01115.84
7.1.250.0040.01115.86
7.1.200.0030.00715.80
7.1.100.0060.00917.87
7.1.70.0000.00717.25
7.1.60.0090.01519.32
7.1.50.0040.01817.08
7.1.00.0070.07322.57
7.0.200.0040.00416.89
7.0.140.0070.07021.99
7.0.90.0570.07319.91
7.0.80.0470.05019.91
7.0.70.0330.07019.95
7.0.60.0600.08719.91
7.0.50.0470.05020.30
7.0.40.0100.05019.95
7.0.30.0100.04020.16
7.0.20.0130.07020.12
7.0.10.0170.07320.13
7.0.00.0070.04319.98
5.6.280.0000.07721.14
5.6.240.0130.05020.66
5.6.230.0030.08720.64
5.6.220.0100.08020.66
5.6.210.0100.08020.51
5.6.200.0070.08321.14
5.6.190.0100.07320.97
5.6.180.0030.04721.15
5.6.170.0130.06721.18
5.6.160.0130.06721.06
5.6.150.0100.04020.97
5.6.140.0100.08320.96
5.6.130.0070.05721.07
5.6.120.0070.05321.09
5.6.110.0170.03720.93
5.6.100.0030.05721.03
5.6.90.0170.04321.04
5.6.80.0130.08020.43
5.6.70.0070.07720.45
5.6.60.0030.08020.52
5.6.50.0070.08020.44
5.6.40.0000.04720.33
5.6.30.0070.07320.40
5.6.20.0000.06020.54
5.6.10.0030.03720.43
5.6.00.0070.03720.39
5.5.380.0100.05720.50
5.5.370.0030.08320.47
5.5.360.0070.08320.36
5.5.350.0100.05720.38
5.5.340.0030.07020.88
5.5.330.0000.08320.82
5.5.320.0100.07020.86
5.5.310.0100.04320.90
5.5.300.0030.06720.89
5.5.290.0070.08020.78
5.5.280.0070.04320.90
5.5.270.0070.07320.87
5.5.260.0100.04020.90
5.5.250.0100.05720.66
5.5.240.0000.05020.21
5.5.230.0100.07320.26
5.5.220.0070.08020.15
5.5.210.0100.07320.32
5.5.200.0070.07020.18
5.5.190.0030.08320.14
5.5.180.0070.05020.16
5.5.160.0000.04320.24
5.5.150.0070.08020.13
5.5.140.0100.05020.13
5.5.130.0030.06020.26
5.5.120.0030.08320.25
5.5.110.0070.07720.12
5.5.100.0070.04020.09
5.5.90.0030.04320.17
5.5.80.0070.06020.09
5.5.70.0070.04019.95
5.5.60.0100.07320.11
5.5.50.0030.07720.13
5.5.40.0070.03720.16
5.5.30.0170.06720.09
5.5.20.0030.04320.05
5.5.10.0030.04719.98
5.5.00.0100.04720.04
5.4.450.0000.08719.20
5.4.440.0030.08719.38
5.4.430.0130.07319.41
5.4.420.0100.06019.27
5.4.410.0130.07019.36
5.4.400.0100.04318.88
5.4.390.0030.07718.88
5.4.380.0100.07719.03
5.4.370.0000.04319.19
5.4.360.0070.04019.09
5.4.350.0000.04719.05
5.4.340.0000.04318.98
5.4.320.0000.03718.91
5.4.310.0030.04019.16
5.4.300.0000.08019.16
5.4.290.0070.03018.94
5.4.280.0070.07019.08
5.4.270.0100.07319.08
5.4.260.0070.05319.04
5.4.250.0030.03719.16
5.4.240.0100.05719.21
5.4.230.0100.04319.02
5.4.220.0100.08019.18
5.4.210.0030.05319.02
5.4.200.0100.03318.89
5.4.190.0130.04318.89
5.4.180.0100.05718.94
5.4.170.0030.03719.04
5.4.160.0070.04719.14
5.4.150.0070.05718.85
5.4.140.0000.07016.39
5.4.130.0000.03716.41
5.4.120.0070.06316.36
5.4.110.0030.07316.48
5.4.100.0030.03716.43
5.4.90.0070.05716.42
5.4.80.0030.07316.33
5.4.70.0070.07016.35
5.4.60.0000.08016.48
5.4.50.0100.06316.47
5.4.40.0070.07016.35
5.4.30.0030.04316.33
5.4.20.0070.03316.48
5.4.10.0000.08016.45
5.4.00.0070.07315.81
5.3.290.0070.06714.78
5.3.280.0100.04014.52
5.3.270.0030.03714.58
5.3.260.0100.07314.61
5.3.250.0030.06014.72
5.3.240.0030.05314.58
5.3.230.0030.04714.66
5.3.220.0070.07014.59
5.3.210.0130.03714.58
5.3.200.0070.04314.57
5.3.190.0000.04014.59
5.3.180.0030.06714.57
5.3.170.0030.05314.49
5.3.160.0070.05014.53
5.3.150.0070.04014.58
5.3.140.0130.06314.65
5.3.130.0070.04714.64
5.3.120.0030.04714.55
5.3.110.0070.04314.47
5.3.100.0070.07314.00
5.3.90.0130.06013.98
5.3.80.0100.04713.99
5.3.70.0030.05014.13
5.3.60.0070.07313.90
5.3.50.0170.04714.05
5.3.40.0000.08013.83
5.3.30.0030.05313.84
5.3.20.0030.04313.71
5.3.10.0070.05013.77
5.3.00.0030.03713.77
5.2.170.0000.03711.20
5.2.160.0000.03311.17
5.2.150.0130.05311.26
5.2.140.0070.06011.20
5.2.130.0030.04311.22
5.2.120.0070.06311.10
5.2.110.0030.03011.11
5.2.100.0000.06711.18
5.2.90.0000.05011.14
5.2.80.0130.05310.99
5.2.70.0070.05011.12
5.2.60.0130.05311.04
5.2.50.0030.04011.15
5.2.40.0100.02011.02
5.2.30.0030.04010.83
5.2.20.0030.02710.98
5.2.10.0000.03710.99
5.2.00.0030.03010.63
5.1.60.0030.02310.03
5.1.50.0000.05710.11
5.1.40.0000.03710.00
5.1.30.0000.05310.47
5.1.20.0000.02710.43
5.1.10.0000.0239.91
5.1.00.0000.03710.15
5.0.50.0070.0138.57
5.0.40.0070.0338.25
5.0.30.0030.0608.20
5.0.20.0030.0238.23
5.0.10.0030.0308.26
5.0.00.0070.0278.24
4.4.90.0000.0207.39
4.4.80.0000.0307.39
4.4.70.0000.0177.39
4.4.60.0000.0377.39
4.4.50.0000.0237.39
4.4.40.0030.0337.39
4.4.30.0030.0307.39
4.4.20.0030.0307.39
4.4.10.0000.0137.39
4.4.00.0030.0207.39
4.3.110.0000.0137.39
4.3.100.0070.0307.39
4.3.90.0000.0337.39
4.3.80.0000.0537.39
4.3.70.0030.0107.39
4.3.60.0030.0137.39
4.3.50.0000.0377.39
4.3.40.0000.0577.39
4.3.30.0030.0207.39
4.3.20.0000.0337.39
4.3.10.0030.0237.39
4.3.00.0030.0137.39

preferences:
40.27 ms | 400 KiB | 5 Q