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 DataHolder($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.0110.00418.28
8.3.50.0120.00618.06
8.3.40.0070.01018.83
8.3.30.0030.01019.04
8.3.20.0040.00420.16
8.3.10.0080.00020.52
8.3.00.0030.00519.27
8.2.180.0070.00716.88
8.2.170.0110.00422.96
8.2.160.0110.00720.52
8.2.150.0000.00724.18
8.2.140.0070.01124.66
8.2.130.0030.00526.16
8.2.120.0050.00222.20
8.2.110.0040.00420.38
8.2.100.0000.01117.91
8.2.90.0080.00019.14
8.2.80.0050.00317.97
8.2.70.0080.00017.50
8.2.60.0030.00517.55
8.2.50.0040.00418.07
8.2.40.0060.00318.22
8.2.30.0000.00818.08
8.2.20.0070.00017.61
8.2.10.0040.00418.10
8.2.00.0000.00917.63
8.1.280.0100.00325.92
8.1.270.0040.00422.24
8.1.260.0000.00726.35
8.1.250.0080.00028.09
8.1.240.0030.00624.02
8.1.230.0040.00719.15
8.1.220.0040.00417.74
8.1.210.0000.00818.77
8.1.200.0000.00917.22
8.1.190.0000.00817.25
8.1.180.0000.00818.10
8.1.170.0000.00818.62
8.1.160.0070.00021.81
8.1.150.0000.00718.82
8.1.140.0070.00017.45
8.1.130.0000.00717.71
8.1.120.0000.00717.43
8.1.110.0040.00417.50
8.1.100.0040.00417.34
8.1.90.0040.00417.46
8.1.80.0000.00717.39
8.1.70.0000.00817.37
8.1.60.0030.00917.44
8.1.50.0000.00917.54
8.1.40.0000.00817.45
8.1.30.0040.00417.71
8.1.20.0070.00017.64
8.1.10.0030.00517.47
8.1.00.0000.00917.41
8.0.300.0000.00718.77
8.0.290.0070.00016.63
8.0.280.0000.00718.40
8.0.270.0070.00017.32
8.0.260.0030.00317.27
8.0.250.0070.00016.97
8.0.240.0040.00416.99
8.0.230.0030.00516.94
8.0.220.0000.00716.80
8.0.210.0000.00716.88
8.0.200.0000.00616.89
8.0.190.0030.00516.89
8.0.180.0040.00416.92
8.0.170.0040.00416.92
8.0.160.0040.00416.94
8.0.150.0000.00716.86
8.0.140.0000.00716.78
8.0.130.0050.00013.38
8.0.120.0030.00516.85
8.0.110.0000.00716.80
8.0.100.0000.00816.92
8.0.90.0000.00717.01
8.0.80.0030.01116.95
8.0.70.0030.00616.78
8.0.60.0030.00316.85
8.0.50.0020.00516.96
8.0.30.0080.01116.96
8.0.20.0070.01217.40
8.0.10.0000.00817.09
8.0.00.0060.01116.68
7.4.330.0000.00615.00
7.4.320.0030.00316.54
7.4.300.0000.00816.46
7.4.290.0000.00716.54
7.4.280.0040.00416.58
7.4.270.0040.00416.51
7.4.260.0030.00316.64
7.4.250.0040.00416.48
7.4.240.0040.00416.51
7.4.230.0000.00716.31
7.4.220.0060.01316.46
7.4.210.0200.00316.73
7.4.200.0050.00316.59
7.4.160.0110.01116.56
7.4.150.0120.00617.40
7.4.140.0070.01017.86
7.4.130.0130.00316.54
7.4.120.0080.00816.51
7.4.110.0070.01116.51
7.4.100.0090.00816.61
7.4.90.0190.00016.63
7.4.80.0100.00719.39
7.4.70.0120.01116.68
7.4.60.0080.00816.41
7.4.50.0050.00016.41
7.4.40.0100.00716.58
7.4.30.0090.01316.51
7.4.00.0130.00315.17
7.3.330.0050.00013.34
7.3.320.0030.00313.25
7.3.310.0030.00316.36
7.3.300.0070.00016.32
7.3.290.0030.01016.36
7.3.280.0060.01116.31
7.3.270.0150.00417.40
7.3.260.0120.00616.32
7.3.250.0100.00716.29
7.3.240.0120.00416.55
7.3.230.0080.00816.44
7.3.210.0030.01616.48
7.3.200.0110.01219.39
7.3.190.0080.01116.45
7.3.180.0090.00616.33
7.3.170.0090.00616.32
7.3.160.0160.00016.34
7.3.10.0000.01716.27
7.3.00.0070.00716.32
7.2.330.0060.01216.48
7.2.320.0060.01516.64
7.2.310.0070.01316.34
7.2.300.0130.00316.48
7.2.290.0120.00616.51
7.2.130.0070.01016.14
7.2.120.0040.00816.33
7.2.110.0060.00816.15
7.2.100.0090.00616.31
7.2.90.0090.00616.58
7.2.80.0130.00016.39
7.2.70.0140.00016.57
7.2.60.0050.00816.67
7.2.50.0090.00416.46
7.2.40.0070.01016.55
7.2.30.0100.00016.58
7.2.20.0030.00916.34
7.2.10.0060.00916.42
7.2.00.0070.00416.57
7.1.250.0080.00315.50
7.1.200.0300.00015.20
7.1.70.0030.00616.79
7.1.60.0060.01819.32
7.1.50.0030.01916.80
7.1.00.0070.07022.35
7.0.200.0000.00816.34
7.0.140.0000.07721.98
7.0.90.0570.04019.98
7.0.80.0230.03319.92
7.0.70.0500.05319.98
7.0.60.0530.06319.87
7.0.50.0170.04720.14
7.0.40.0070.08020.07
7.0.30.0170.07020.05
7.0.20.0130.05720.13
7.0.10.0030.08720.14
7.0.00.0130.07720.05
5.6.280.0000.07720.92
5.6.240.0030.05720.62
5.6.230.0100.04020.51
5.6.220.0030.04720.67
5.6.210.0100.03320.66
5.6.200.0000.04721.10
5.6.190.0030.04021.15
5.6.180.0100.05721.13
5.6.170.0070.09021.05
5.6.160.0130.07721.04
5.6.150.0030.08021.04
5.6.140.0030.06321.03
5.6.130.0100.05721.05
5.6.120.0070.08021.14
5.6.110.0100.07321.02
5.6.100.0070.07321.03
5.6.90.0100.08320.93
5.6.80.0170.06720.35
5.6.70.0270.06320.41
5.6.60.0100.07720.41
5.6.50.0030.08720.36
5.6.40.0070.08720.44
5.6.30.0100.05720.38
5.6.20.0070.05320.45
5.6.10.0030.06320.54
5.6.00.0070.08320.48
5.5.380.0070.04020.37
5.5.370.0100.04720.50
5.5.360.0100.04020.56
5.5.350.0070.04020.37
5.5.340.0100.04020.82
5.5.330.0070.03320.84
5.5.320.0130.04720.89
5.5.310.0100.07720.65
5.5.300.0070.04320.84
5.5.290.0100.04020.79
5.5.280.0030.08320.94
5.5.270.0000.06020.88
5.5.260.0100.07720.73
5.5.250.0030.07320.44
5.5.240.0130.06020.30
5.5.230.0070.08020.15
5.5.220.0130.07020.21
5.5.210.0130.07720.23
5.5.200.0030.07020.09
5.5.190.0070.08720.14
5.5.180.0030.08020.26
5.5.160.0030.08320.26
5.5.150.0030.04020.16
5.5.140.0070.07720.23
5.5.130.0130.06019.95
5.5.120.0100.07720.18
5.5.110.0000.06320.10
5.5.100.0000.04720.09
5.5.90.0030.07720.02
5.5.80.0070.04720.11
5.5.70.0100.07320.13
5.5.60.0100.07720.07
5.5.50.0030.08020.16
5.5.40.0070.07020.16
5.5.30.0030.08320.05
5.5.20.0100.08020.04
5.5.10.0100.08020.09
5.5.00.0070.04020.09
5.4.450.0130.07319.20
5.4.440.0070.07319.36
5.4.430.0030.06719.36
5.4.420.0000.06019.20
5.4.410.0200.06319.20
5.4.400.0030.08719.04
5.4.390.0100.07319.20
5.4.380.0070.08019.09
5.4.370.0000.08019.16
5.4.360.0200.05319.03
5.4.350.0070.04719.03
5.4.340.0100.06319.11
5.4.320.0030.08018.93
5.4.310.0170.03319.20
5.4.300.0070.07719.02
5.4.290.0070.07719.12
5.4.280.0130.06718.81
5.4.270.0070.07719.14
5.4.260.0030.07719.14
5.4.250.0000.08718.84
5.4.240.0100.06719.04
5.4.230.0070.07319.12
5.4.220.0030.06319.02
5.4.210.0070.07319.07
5.4.200.0030.06719.20
5.4.190.0170.06018.83
5.4.180.0100.06019.11
5.4.170.0070.04719.11
5.4.160.0100.07018.91
5.4.150.0100.04319.11
5.4.140.0030.06016.21
5.4.130.0070.06716.38
5.4.120.0070.06016.39
5.4.110.0130.04016.36
5.4.100.0100.07016.28
5.4.90.0200.06316.32
5.4.80.0070.03716.31
5.4.70.0030.05016.32
5.4.60.0070.03316.48
5.4.50.0100.06316.47
5.4.40.0100.06716.45
5.4.30.0030.07316.45
5.4.20.0100.07016.33
5.4.10.0100.07716.32
5.4.00.0030.07315.86
5.3.290.0070.05014.69
5.3.280.0070.05314.60
5.3.270.0100.07014.69
5.3.260.0000.08314.63
5.3.250.0000.06014.55
5.3.240.0070.06714.58
5.3.230.0100.07314.52
5.3.220.0070.07014.54
5.3.210.0030.08314.67
5.3.200.0070.06314.48
5.3.190.0100.06714.49
5.3.180.0030.07314.48
5.3.170.0070.08014.68
5.3.160.0100.07314.54
5.3.150.0130.07014.48
5.3.140.0030.07014.45
5.3.130.0000.05014.52
5.3.120.0100.07014.68
5.3.110.0030.08014.46
5.3.100.0030.07314.03
5.3.90.0030.04314.08
5.3.80.0000.05314.11
5.3.70.0070.07313.94
5.3.60.0100.06313.92
5.3.50.0030.08013.93
5.3.40.0030.05313.83
5.3.30.0030.04313.99
5.3.20.0070.06013.62
5.3.10.0070.06313.73
5.3.00.0070.07013.70
5.2.170.0100.05311.03
5.2.160.0100.05311.14
5.2.150.0030.05711.23
5.2.140.0100.06011.05
5.2.130.0170.05311.22
5.2.120.0000.05311.22
5.2.110.0030.06311.14
5.2.100.0030.04011.12
5.2.90.0000.06011.13
5.2.80.0030.06711.02
5.2.70.0030.04711.12
5.2.60.0030.03310.95
5.2.50.0070.05711.02
5.2.40.0070.05311.00
5.2.30.0070.04710.88
5.2.20.0070.05711.07
5.2.10.0070.05010.76
5.2.00.0030.06310.82
5.1.60.0000.06010.06
5.1.50.0070.0509.98
5.1.40.0070.0439.81
5.1.30.0030.04710.34
5.1.20.0030.03710.41
5.1.10.0000.05010.18
5.1.00.0030.05710.17
5.0.50.0000.0378.54
5.0.40.0070.0208.40
5.0.30.0030.0338.22
5.0.20.0070.0408.25
5.0.10.0030.0238.24
5.0.00.0030.0678.15
4.4.90.0030.0207.35
4.4.80.0070.0307.35
4.4.70.0000.0377.35
4.4.60.0000.0337.35
4.4.50.0000.0377.35
4.4.40.0030.0537.35
4.4.30.0070.0337.35
4.4.20.0000.0407.35
4.4.10.0000.0337.35
4.4.00.0070.0477.35
4.3.110.0000.0377.35
4.3.100.0030.0337.35
4.3.90.0000.0337.35
4.3.80.0070.0507.35
4.3.70.0000.0307.35
4.3.60.0070.0207.35
4.3.50.0000.0237.35
4.3.40.0030.0477.35
4.3.30.0030.0337.35
4.3.20.0030.0277.35
4.3.10.0030.0277.35
4.3.00.0030.0307.35

preferences:
48.16 ms | 400 KiB | 5 Q