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 $dm = new DataMapper($data); // The data is parsed so it can be var_dump($dm->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.40.0140.00418.84
8.3.30.0070.00719.13
8.3.20.0040.00420.46
8.3.10.0090.00020.52
8.3.00.0030.00519.38
8.2.170.0140.00022.96
8.2.160.0030.01220.36
8.2.150.0070.00024.18
8.2.140.0040.01124.66
8.2.130.0000.00726.16
8.2.120.0040.00420.84
8.2.110.0100.00020.58
8.2.100.0080.00418.22
8.2.90.0040.00419.39
8.2.80.0050.00317.97
8.2.70.0030.00617.50
8.2.60.0030.00517.93
8.2.50.0050.00318.07
8.2.40.0040.00418.28
8.2.30.0040.00418.18
8.2.20.0080.00017.75
8.2.10.0050.00218.00
8.2.00.0050.00217.74
8.1.270.0080.00022.24
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00723.98
8.1.230.0060.00619.17
8.1.220.0080.00017.79
8.1.210.0040.00418.77
8.1.200.0090.00017.23
8.1.190.0040.00417.13
8.1.180.0050.00218.10
8.1.170.0000.00818.59
8.1.160.0000.00722.03
8.1.150.0040.00418.75
8.1.140.0030.00617.46
8.1.130.0040.00417.83
8.1.120.0070.00017.38
8.1.110.0070.00017.37
8.1.100.0070.00017.54
8.1.90.0030.00317.53
8.1.80.0040.00417.35
8.1.70.0000.00717.46
8.1.60.0050.00517.63
8.1.50.0040.00417.57
8.1.40.0000.00817.51
8.1.30.0080.00017.70
8.1.20.0040.00417.49
8.1.10.0040.00417.54
8.1.00.0020.00517.55
8.0.300.0000.00918.77
8.0.290.0000.00716.75
8.0.280.0030.00318.51
8.0.270.0070.00016.83
8.0.260.0000.00617.23
8.0.250.0000.00716.91
8.0.240.0050.00317.04
8.0.230.0040.00416.98
8.0.220.0040.00416.91
8.0.210.0040.00416.92
8.0.200.0030.00317.02
8.0.190.0050.00316.86
8.0.180.0040.00416.91
8.0.170.0040.00416.95
8.0.160.0030.00316.80
8.0.150.0000.00716.71
8.0.140.0050.00316.77
8.0.130.0040.00313.45
8.0.120.0000.00816.84
8.0.110.0040.00416.84
8.0.100.0000.00716.80
8.0.90.0020.00516.75
8.0.80.0070.00716.95
8.0.70.0040.00416.79
8.0.60.0000.00716.78
8.0.50.0040.00416.91
8.0.30.0070.01217.27
8.0.20.0090.01017.40
8.0.10.0060.00316.94
8.0.00.0060.01316.87
7.4.330.0050.00015.01
7.4.320.0000.00616.65
7.4.300.0040.00416.53
7.4.290.0000.00716.54
7.4.280.0080.00016.55
7.4.270.0070.00016.61
7.4.260.0030.00316.64
7.4.250.0000.00716.42
7.4.240.0030.00316.57
7.4.230.0000.00716.57
7.4.220.0000.01816.42
7.4.210.0090.00616.64
7.4.200.0030.00316.51
7.4.160.0080.00816.51
7.4.150.0100.00717.40
7.4.140.0090.00917.86
7.4.130.0070.01016.54
7.4.120.0120.00616.48
7.4.110.0100.00716.48
7.4.100.0140.00416.43
7.4.90.0100.01016.61
7.4.80.0080.00819.39
7.4.70.0030.01516.51
7.4.60.0120.00616.48
7.4.50.0050.00316.51
7.4.40.0100.00716.63
7.4.30.0100.00616.60
7.4.00.0060.01014.66
7.3.330.0030.00313.24
7.3.320.0000.00513.20
7.3.310.0040.00416.28
7.3.300.0070.00016.38
7.3.290.0110.00816.43
7.3.280.0090.00716.39
7.3.270.0060.01217.40
7.3.260.0130.00416.63
7.3.250.0070.01316.38
7.3.240.0080.00816.39
7.3.230.0100.00716.39
7.3.210.0030.01616.39
7.3.200.0100.00619.39
7.3.190.0070.01416.39
7.3.180.0120.00416.60
7.3.170.0060.01016.66
7.3.160.0110.00516.48
7.3.10.0060.00616.61
7.3.00.0110.00416.62
7.2.330.0120.00616.84
7.2.320.0120.01216.87
7.2.310.0070.01116.74
7.2.300.0070.01016.76
7.2.290.0080.01216.83
7.2.130.0140.00316.94
7.2.120.0090.00316.92
7.2.110.0040.00816.88
7.2.100.0040.00716.98
7.2.90.0090.00317.09
7.2.80.0060.00616.57
7.2.70.0030.00916.85
7.2.60.0120.00916.97
7.2.50.0040.00816.80
7.2.40.0040.01117.13
7.2.30.0090.00916.98
7.2.20.0100.00317.06
7.2.10.0110.00717.06
7.2.00.0030.00716.86
7.1.250.0100.00015.65
7.1.200.0070.00715.79
7.1.70.0040.00416.82
7.1.60.0070.01719.32
7.1.50.0130.01016.98
7.1.00.0100.07022.31
7.0.200.0000.01016.80
7.0.140.0000.07722.09
7.0.60.0000.04320.09
7.0.50.0030.08017.89
7.0.40.0070.07320.18
7.0.30.0570.06720.11
7.0.20.0230.06720.30
7.0.10.0100.04320.08
7.0.00.0070.04020.10
5.6.280.0000.07720.88
5.6.210.0170.06720.60
5.6.200.0070.04318.19
5.6.190.0000.06320.41
5.6.180.0230.06720.45
5.6.170.0270.05320.55
5.6.160.0070.08320.44
5.6.150.0100.07318.17
5.6.140.0200.04718.28
5.6.130.0130.07318.16
5.6.120.0100.07321.00
5.6.110.0130.07720.99
5.6.100.0170.05320.96
5.6.90.0100.06721.13
5.6.80.0070.03720.38
5.6.70.3470.03720.53
5.5.350.0100.05720.33
5.5.340.0070.08717.99
5.5.330.0030.04320.21
5.5.320.0170.04020.32
5.5.310.0200.06720.32
5.5.300.0100.06717.95
5.5.290.0070.04318.08
5.5.280.0030.07720.89
5.5.270.0100.08320.77
5.5.260.0070.08320.80
5.5.250.0170.07020.59
5.5.240.0100.06320.19
5.4.450.0470.04019.55
5.4.440.0930.05019.55
5.4.430.0730.07719.38
5.4.420.0670.00019.63
5.4.410.0630.00019.41
5.4.400.0630.00019.27
5.4.390.0630.00019.07
5.4.380.0700.00019.19
5.4.370.0600.00019.15
5.4.360.0630.00019.24
5.4.350.0700.00019.12
5.4.340.0600.00019.12
5.4.320.0060.03712.51
5.4.310.0060.04512.51
5.4.300.0090.03912.51
5.4.290.0060.03712.50
5.4.280.0080.03212.40
5.4.270.0060.03612.41
5.4.260.0060.03612.41
5.4.250.0090.03812.40
5.4.240.0100.03412.41
5.4.230.0050.04112.40
5.4.220.0050.03612.40
5.4.210.0090.03512.40
5.4.200.0070.03912.40
5.4.190.0060.03912.39
5.4.180.0050.03512.39
5.4.170.0040.03612.41
5.4.160.0020.03912.40
5.4.150.0070.03312.39
5.4.140.0060.03612.08
5.4.130.0060.03412.07
5.4.120.0030.03612.03
5.4.110.0050.03612.02
5.4.100.0060.03512.03
5.4.90.0050.03612.02
5.4.80.0040.03812.02
5.4.70.0040.03512.02
5.4.60.0060.03412.02
5.4.50.0040.04412.02
5.4.40.0070.03612.00
5.4.30.0070.03412.01
5.4.20.0070.03412.01
5.4.10.0040.04012.01
5.4.00.0060.04011.49
5.3.290.0080.03712.80
5.3.280.0080.04412.71
5.3.270.0070.04012.72
5.3.260.0060.04012.72
5.3.250.0060.03812.72
5.3.240.0030.03812.72
5.3.230.0080.03412.71
5.3.220.0090.04112.68
5.3.210.0040.04112.68
5.3.200.0060.04012.68
5.3.190.0050.03812.68
5.3.180.0090.03812.68
5.3.170.0080.03412.67
5.3.160.0060.03612.67
5.3.150.0120.03112.67
5.3.140.0040.03712.66
5.3.130.0030.04012.66
5.3.120.0020.04112.66
5.3.110.0090.03412.66
5.3.100.0070.03412.12
5.3.90.0060.03712.10
5.3.80.0050.03512.09
5.3.70.0090.03312.09
5.3.60.0050.03512.08
5.3.50.0050.04212.02
5.3.40.0060.03412.02
5.3.30.0070.03211.98
5.3.20.0060.03911.76
5.3.10.0060.03911.73
5.3.00.0050.04011.71
5.2.170.0050.0309.21
5.2.160.0050.0289.22
5.2.150.0050.0309.22
5.2.140.0060.0289.22
5.2.130.0070.0299.18
5.2.120.0040.0289.18
5.2.110.0040.0379.18
5.2.100.0100.0259.17
5.2.90.0070.0269.17
5.2.80.0050.0289.17
5.2.70.0060.0369.17
5.2.60.0070.0279.13
5.2.50.0070.0279.10
5.2.40.0080.0269.07
5.2.30.0080.0269.04
5.2.20.0050.0289.04
5.2.10.0040.0288.94
5.2.00.0040.0328.80
5.1.60.0040.0248.09
5.1.50.0030.0258.09
5.1.40.0060.0298.06
5.1.30.0050.0258.41
5.1.20.0060.0248.44
5.1.10.0060.0248.16
5.1.00.0020.0268.16
5.0.50.0050.0186.64
5.0.40.0050.0256.50
5.0.30.0050.0296.32
5.0.20.0020.0206.27
5.0.10.0060.0166.26
5.0.00.0040.0306.25
4.4.90.0050.0134.78
4.4.80.0020.0164.76
4.4.70.0040.0144.75
4.4.60.0020.0164.75
4.4.50.0040.0144.77
4.4.40.0020.0264.71
4.4.30.0040.0144.76
4.4.20.0000.0194.84
4.4.10.0030.0154.85
4.4.00.0010.0274.76
4.3.110.0020.0164.66
4.3.100.0030.0144.66
4.3.90.0010.0164.64
4.3.80.0040.0234.58
4.3.70.0040.0134.63
4.3.60.0060.0124.63
4.3.50.0020.0184.63
4.3.40.0010.0274.53
4.3.30.0010.0183.30
4.3.20.0020.0183.28
4.3.10.0020.0163.24
4.3.00.0100.0138.56

preferences:
44.78 ms | 400 KiB | 5 Q