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' => ['parseFn1', 'parseFn2']] ]; public function __construct(array $data) { $this->rawData = $data; $this->mapData(); } /** * @param $value * @return mixed */ private function parseFn1($value) { return $value * 2; } /** * @param $value * @return string */ private function parseFn2($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)) { $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); } $parsedData[$frontFieldName] = $value; } } } } /** * Simple getter * @return array */ public function getParseData() { return $this->parsedData; } } // Usually the data comes from the DB so it would be in some kind of Row Set structure $data = ['dbField1' => 5, 'dbField2' => 13]; // The data is handed to the Holder which parses it $dh = new DataMapper($data); // The data is parsed so it can be echo json_encode($dh->getParseData());

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.0140.00018.56
8.3.50.0090.01122.12
8.3.40.0110.00418.92
8.3.30.0070.00719.13
8.3.20.0000.00820.16
8.3.10.0050.00320.66
8.3.00.0080.00019.25
8.2.180.0090.00616.38
8.2.170.0040.01122.96
8.2.160.0110.00320.20
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0000.00826.16
8.2.120.0000.00722.31
8.2.110.0060.00320.37
8.2.100.0040.00818.10
8.2.90.0040.00419.39
8.2.80.0050.00317.97
8.2.70.0030.00517.50
8.2.60.0050.00318.05
8.2.50.0080.00018.07
8.2.40.0030.00518.07
8.2.30.0000.00718.01
8.2.20.0040.00417.63
8.2.10.0000.00718.09
8.2.00.0030.00617.56
8.1.280.0080.00625.92
8.1.270.0080.00023.83
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00623.80
8.1.230.0000.01119.01
8.1.220.0050.00317.79
8.1.210.0000.00818.77
8.1.200.0000.00917.38
8.1.190.0030.00517.13
8.1.180.0040.00418.10
8.1.170.0000.00918.49
8.1.160.0050.00221.99
8.1.150.0040.00418.81
8.1.140.0020.00517.47
8.1.130.0030.00317.76
8.1.120.0040.00417.46
8.1.110.0040.00417.45
8.1.100.0040.00417.48
8.1.90.0000.00817.48
8.1.80.0040.00417.38
8.1.70.0070.00017.42
8.1.60.0000.01017.52
8.1.50.0030.00617.43
8.1.40.0040.00417.54
8.1.30.0060.00317.70
8.1.20.0000.00717.69
8.1.10.0000.00717.60
8.1.00.0090.00017.52
8.0.300.0040.00418.77
8.0.290.0040.00416.75
8.0.280.0040.00418.46
8.0.270.0000.00717.27
8.0.260.0070.00017.28
8.0.250.0030.00516.87
8.0.240.0000.00716.96
8.0.230.0080.00016.94
8.0.220.0000.00716.82
8.0.210.0030.00316.81
8.0.200.0000.00616.96
8.0.190.0040.00416.96
8.0.180.0040.00416.83
8.0.170.0000.00816.92
8.0.160.0050.00216.79
8.0.150.0070.00016.84
8.0.140.0000.00716.87
8.0.130.0030.00613.33
8.0.120.0000.00816.98
8.0.110.0000.00716.93
8.0.100.0000.00716.89
8.0.90.0000.00716.80
8.0.80.0100.00616.79
8.0.70.0040.00416.77
8.0.60.0000.00716.82
8.0.50.0000.00716.85
8.0.30.0110.00917.31
8.0.20.0070.01217.40
8.0.10.0030.00617.14
8.0.00.0140.00716.70
7.4.330.0060.00015.00
7.4.320.0000.00616.51
7.4.300.0000.00716.61
7.4.290.0070.00016.59
7.4.280.0080.00016.56
7.4.270.0030.00616.57
7.4.260.0070.00016.39
7.4.250.0040.00416.48
7.4.240.0060.00116.57
7.4.230.0020.00516.71
7.4.220.0120.00916.65
7.4.210.0120.00316.44
7.4.200.0040.00416.68
7.4.160.0120.00416.47
7.4.150.0070.01017.40
7.4.140.0120.00517.86
7.4.130.0090.00716.53
7.4.120.0090.00816.47
7.4.110.0070.01016.49
7.4.100.0080.00816.56
7.4.90.0140.01016.45
7.4.80.0090.00919.39
7.4.70.0030.01416.64
7.4.60.0070.01116.66
7.4.50.0000.00716.45
7.4.40.0120.00916.58
7.4.30.0060.01416.45
7.4.00.0030.01414.80
7.3.330.0050.00013.30
7.3.320.0000.00513.31
7.3.310.0030.00316.43
7.3.300.0000.00716.39
7.3.290.0060.01116.43
7.3.280.0090.00916.37
7.3.270.0100.00717.40
7.3.260.0110.00716.58
7.3.250.0100.00616.53
7.3.240.0110.01216.57
7.3.230.0070.01016.44
7.3.210.0160.00316.35
7.3.200.0170.00319.39
7.3.190.0060.01116.51
7.3.180.0090.00916.43
7.3.170.0070.01016.49
7.3.160.0070.01016.48
7.2.330.0090.00916.78
7.2.320.0100.01216.68
7.2.310.0070.01116.64
7.2.300.0130.00316.78
7.2.290.0030.01516.52
7.2.60.0040.01116.97
7.2.00.0030.00919.24
7.1.200.0040.00815.76
7.1.100.0080.00518.10
7.1.70.0000.00817.17
7.1.60.0100.01419.32
7.1.50.0060.01317.02
7.1.00.0000.07722.57
7.0.200.0070.00316.93
7.0.140.0030.07021.97
7.0.90.0030.07019.88
7.0.80.0070.08019.87
7.0.70.0030.04719.91
7.0.60.0200.05320.07
7.0.50.0600.07320.28
7.0.40.0100.06020.13
7.0.30.0200.06320.13
7.0.20.0030.06020.17
7.0.10.0070.09720.09
7.0.00.0100.07720.10
5.6.240.0070.06720.68
5.6.230.0100.07320.51
5.6.220.0070.05020.49
5.6.210.0030.05320.68
5.6.200.0070.07021.13
5.6.190.0130.03721.18
5.6.180.0130.07320.95
5.6.170.0170.07321.15
5.6.160.0030.07021.02
5.6.150.0130.07021.11
5.6.140.0030.08021.01
5.6.130.0070.08321.14
5.6.120.0000.08721.06
5.6.110.0130.04321.11
5.6.100.0100.06021.00
5.6.90.0170.07721.07
5.6.80.0130.07320.48
5.6.70.0000.05020.41
5.6.60.0030.07020.41
5.6.50.0070.05720.42
5.6.40.0100.06320.40
5.6.30.0070.03720.39
5.6.20.0100.06720.32
5.6.10.0130.07720.42
5.6.00.0030.05320.37
5.5.380.0030.07720.51
5.5.370.0200.07020.40
5.5.360.0030.08020.42
5.5.350.0030.08720.46
5.5.340.0070.08020.84
5.5.330.0130.03720.79
5.5.320.0030.08020.91
5.5.310.0100.07020.64
5.5.300.0070.07020.74
5.5.290.0030.08320.84
5.5.280.0070.06720.81
5.5.270.0070.04320.86
5.5.260.0100.07320.79
5.5.250.0070.06020.74
5.5.240.0100.04020.32
5.5.230.0130.07720.25
5.5.220.0100.06720.18
5.5.210.0070.03720.19
5.5.200.0130.08020.12
5.5.190.0070.08020.14
5.5.180.0100.07320.25
5.5.160.0100.05320.26
5.5.150.0030.05020.20
5.5.140.0030.08020.22
5.5.130.0070.05320.29
5.5.120.0330.06320.25
5.5.110.0000.07720.15
5.5.100.0030.04020.06
5.5.90.0030.08020.08
5.5.80.0100.07720.06
5.5.70.0100.07020.10
5.5.60.0070.05320.16
5.5.50.0100.07020.07
5.5.40.0070.07020.16
5.5.30.0070.04720.16
5.5.20.0100.08320.06
5.5.10.0100.05720.01
5.5.00.0230.07020.03
5.4.450.0130.07319.51
5.4.440.0100.08019.41
5.4.430.0000.04319.35
5.4.420.0070.08019.44
5.4.410.0130.03719.26
5.4.400.0030.04019.16
5.4.390.0070.04719.18
5.4.380.0070.06319.23
5.4.370.0030.04719.04
5.4.360.0030.07319.05
5.4.350.0070.06019.03
5.4.340.0000.04319.04
5.4.320.0030.08019.16
5.4.310.0000.08019.04
5.4.300.0070.07719.02
5.4.290.0170.07019.04
5.4.280.0030.08319.04
5.4.270.0070.06319.04
5.4.260.0100.03719.12
5.4.250.0030.03719.20
5.4.240.0000.04718.94
5.4.230.0030.08019.11
5.4.220.0030.04019.04
5.4.210.0130.05319.12
5.4.200.0100.04719.17
5.4.190.0000.05019.17
5.4.180.0030.07719.23
5.4.170.0070.07019.17
5.4.160.0070.07719.10
5.4.150.0030.07019.02
5.4.140.0200.06716.39
5.4.130.0130.05716.40
5.4.120.0000.04716.44
5.4.110.0070.03716.52
5.4.100.0130.05316.36
5.4.90.0070.07016.34
5.4.80.0100.06716.48
5.4.70.0070.04016.49
5.4.60.0200.05716.31
5.4.50.0000.05316.31
5.4.40.0030.06316.30
5.4.30.0130.05316.46
5.4.20.0030.04316.25
5.4.10.0070.07016.29
5.4.00.0130.03315.74
5.3.290.0070.06714.80
5.3.280.0000.07014.52
5.3.270.0100.07714.61
5.3.260.0070.04314.74
5.3.250.0100.07714.71
5.3.240.0100.07714.57
5.3.230.0130.05714.66
5.3.220.0000.04314.46
5.3.210.0070.04714.51
5.3.200.0130.03014.49
5.3.190.0070.04314.48
5.3.180.0100.03714.68
5.3.170.0030.08314.61
5.3.160.0000.04314.68
5.3.150.0030.06714.52
5.3.140.0130.07014.67
5.3.130.0200.05714.51
5.3.120.0000.04714.57
5.3.110.0000.08314.65
5.3.100.0130.06714.10
5.3.90.0100.06713.94
5.3.80.0130.06714.00
5.3.70.0070.05014.07
5.3.60.0070.06714.03
5.3.50.0170.06314.05
5.3.40.0070.05013.87
5.3.30.0070.04013.91
5.3.20.0070.06313.68
5.3.10.0130.06013.68
5.3.00.0070.07013.69
5.2.170.0070.05711.13
5.2.160.0000.04311.07
5.2.150.0070.05311.25
5.2.140.0030.04011.27
5.2.130.0000.05711.09
5.2.120.0030.05711.03
5.2.110.0000.03711.21
5.2.100.0070.06011.22
5.2.90.0030.03711.10
5.2.80.0070.03311.01
5.2.70.0070.06011.14
5.2.60.0070.03011.18
5.2.50.0030.03710.87
5.2.40.0070.06311.04
5.2.30.0000.03711.09
5.2.20.0070.05711.08
5.2.10.0030.05710.81
5.2.00.0030.03010.83
5.1.60.0070.0509.84
5.1.50.0000.06010.08
5.1.40.0070.05310.00
5.1.30.0030.06310.40
5.1.20.0070.06010.48
5.1.10.0030.0279.91
5.1.00.0070.0509.90
5.0.50.0000.0278.57
5.0.40.0100.0338.46
5.0.30.0070.0608.21
5.0.20.0030.0438.29
5.0.10.0030.0478.22
5.0.00.0000.0508.04
4.4.90.0000.0307.21
4.4.80.0000.0307.21
4.4.70.0030.0377.21
4.4.60.0000.0277.21
4.4.50.0000.0207.21
4.4.40.0030.0377.21
4.4.30.0070.0137.21
4.4.20.0000.0207.21
4.4.10.0070.0337.21
4.4.00.0030.0537.21
4.3.110.0030.0337.21
4.3.100.0030.0307.21
4.3.90.0030.0337.21
4.3.80.0000.0477.21
4.3.70.0030.0337.21
4.3.60.0100.0077.21
4.3.50.0000.0207.21
4.3.40.0030.0537.21
4.3.30.0030.0277.21
4.3.20.0000.0307.21
4.3.10.0000.0307.21
4.3.00.0070.0177.21

preferences:
36.73 ms | 401 KiB | 5 Q