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)) { $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 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);

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.0090.00618.38
8.3.50.0070.01321.28
8.3.40.0030.01218.73
8.3.30.0140.00019.22
8.3.20.0050.00320.16
8.3.10.0000.00920.52
8.3.00.0050.00519.22
8.2.180.0080.01518.29
8.2.170.0090.00619.08
8.2.160.0130.00022.96
8.2.150.0000.00825.66
8.2.140.0090.00024.66
8.2.130.0050.00226.16
8.2.120.0040.00422.11
8.2.110.0150.00722.24
8.2.100.0120.00018.16
8.2.90.0030.00519.22
8.2.80.0060.00317.97
8.2.70.0030.00617.63
8.2.60.0000.00818.05
8.2.50.0050.00318.07
8.2.40.0040.00418.22
8.2.30.0000.00818.15
8.2.20.0000.00817.68
8.2.10.0040.00418.05
8.2.00.0040.00417.66
8.1.280.0120.00325.92
8.1.270.0090.00021.94
8.1.260.0050.00326.35
8.1.250.0050.00328.09
8.1.240.0060.00323.91
8.1.230.0050.00519.02
8.1.220.0050.00317.78
8.1.210.0030.00518.77
8.1.200.0030.00617.23
8.1.190.0060.00317.36
8.1.180.0080.00018.10
8.1.170.0040.00418.59
8.1.160.0050.00322.02
8.1.150.0040.00418.96
8.1.140.0040.00417.36
8.1.130.0030.00317.89
8.1.120.0070.00017.51
8.1.110.0040.00417.46
8.1.100.0060.00317.38
8.1.90.0070.00017.47
8.1.80.0030.00517.53
8.1.70.0080.00017.33
8.1.60.0040.00717.62
8.1.50.0030.00517.39
8.1.40.0040.00417.41
8.1.30.0030.00617.57
8.1.20.0000.00817.71
8.1.10.0080.00017.64
8.1.00.0000.00817.50
8.0.300.0080.00018.77
8.0.290.0040.00416.88
8.0.280.0000.00718.46
8.0.270.0040.00417.18
8.0.260.0000.00617.28
8.0.250.0030.00316.96
8.0.240.0030.00316.88
8.0.230.0000.00716.87
8.0.220.0000.00717.00
8.0.210.0000.00816.92
8.0.200.0030.00316.85
8.0.190.0040.00416.99
8.0.180.0040.00416.88
8.0.170.0040.00417.00
8.0.160.0070.00016.86
8.0.150.0070.00016.88
8.0.140.0000.00716.88
8.0.130.0090.00013.36
8.0.120.0000.00916.88
8.0.110.0040.00416.91
8.0.100.0030.00516.74
8.0.90.0040.00416.98
8.0.80.0100.00716.87
8.0.70.0070.00016.82
8.0.60.0000.00716.90
8.0.50.0030.00516.77
8.0.30.0110.00917.05
8.0.20.0120.00817.40
8.0.10.0080.00016.93
8.0.00.0090.00916.76
7.4.330.0030.00215.09
7.4.320.0030.00316.48
7.4.300.0000.00716.52
7.4.290.0030.00316.60
7.4.280.0000.00716.38
7.4.270.0030.00316.57
7.4.260.0000.00716.57
7.4.250.0040.00416.64
7.4.240.0050.00216.50
7.4.230.0070.00016.41
7.4.220.0030.01616.49
7.4.210.0040.01316.60
7.4.200.0050.00216.69
7.4.160.0140.00216.55
7.4.150.0060.01317.40
7.4.140.0100.00817.86
7.4.130.0050.01316.63
7.4.120.0160.00416.60
7.4.110.0140.00716.40
7.4.100.0040.01416.51
7.4.90.0120.00616.65
7.4.80.0090.00919.39
7.4.70.0060.01616.77
7.4.60.0070.01416.38
7.4.50.0060.00316.37
7.4.40.0160.00716.28
7.4.30.0200.00316.41
7.4.00.0030.01214.75
7.3.330.0030.00313.32
7.3.320.0030.00313.34
7.3.310.0040.00416.23
7.3.300.0030.00316.40
7.3.290.0040.01216.26
7.3.280.0060.01116.35
7.3.270.0100.01017.40
7.3.260.0140.00316.53
7.3.250.0110.00816.52
7.3.240.0110.00716.50
7.3.230.0110.00716.39
7.3.210.0110.00716.37
7.3.200.0120.00919.39
7.3.190.0090.00916.65
7.3.180.0080.00816.24
7.3.170.0110.00616.40
7.3.160.0100.00616.44
7.3.10.0070.00416.73
7.3.00.0090.00016.59
7.2.330.0100.00716.76
7.2.320.0090.01316.64
7.2.310.0070.01016.71
7.2.300.0130.00416.61
7.2.290.0100.01016.82
7.2.130.0090.00017.00
7.2.120.0030.01016.74
7.2.110.0030.01517.03
7.2.100.0000.01516.78
7.2.90.0060.01017.16
7.2.80.0070.00316.80
7.2.70.0070.01016.95
7.2.60.0050.01016.99
7.2.50.0050.00517.04
7.2.40.0030.01016.91
7.2.30.0030.01016.97
7.2.20.0100.00317.17
7.2.10.0060.00316.80
7.2.00.0050.01118.02
7.1.250.0000.01216.01
7.1.200.0090.00315.95
7.1.100.0040.00717.93
7.1.70.0000.00817.34
7.1.60.0130.01019.32
7.1.50.0070.01616.69
7.1.00.0030.07722.35
7.0.200.0000.01016.77
7.0.140.0070.07022.21
7.0.60.0070.07719.95
7.0.50.0100.08017.88
7.0.40.0070.06020.40
7.0.30.0130.04720.20
7.0.20.0200.04720.09
7.0.10.0230.07720.07
7.0.00.0130.07320.07
5.6.280.0100.07021.14
5.6.210.0370.06020.70
5.6.200.0070.08718.19
5.6.190.0170.08020.52
5.6.180.0030.05020.46
5.6.170.0200.05320.45
5.6.160.0100.07720.57
5.6.150.0030.07018.19
5.6.140.0070.03318.18
5.6.130.0030.08718.21
5.6.120.0070.04321.01
5.6.110.0070.04321.05
5.6.100.0130.08721.01
5.6.90.0070.08021.04
5.6.80.0170.07020.50
5.6.70.0270.04320.44
5.5.350.0070.08320.55
5.5.340.0070.03317.99
5.5.330.0030.08720.29
5.5.320.0170.04320.19
5.5.310.0270.06720.19
5.5.300.0170.07017.93
5.5.290.0030.05017.95
5.5.280.0200.06720.79
5.5.270.0070.05720.69
5.5.260.0230.06720.74
5.5.250.0070.07720.51
5.5.240.0130.07720.18
5.4.450.0430.04019.57
5.4.440.1000.06019.49
5.4.430.0970.05019.46
5.4.420.0670.00019.21
5.4.410.0630.00019.41
5.4.400.0630.00019.23
5.4.390.0630.00019.26
5.4.380.0670.00019.07
5.4.370.0600.00019.02
5.4.360.0600.00018.97
5.4.350.0630.00019.12
5.4.340.0670.00019.13
5.4.320.0060.03612.51
5.4.310.0060.03912.51
5.4.300.0110.03112.51
5.4.290.0070.03612.51
5.4.280.0050.03812.41
5.4.270.0060.03612.40
5.4.260.0040.04012.41
5.4.250.0060.04112.41
5.4.240.0070.03312.40
5.4.230.0090.03412.39
5.4.220.0030.03712.39
5.4.210.0050.04612.40
5.4.200.0120.04512.40
5.4.190.0050.04312.39
5.4.180.0100.03712.39
5.4.170.0090.03612.40
5.4.160.0040.03712.41
5.4.150.0050.03612.39
5.4.140.0050.03912.08
5.4.130.0050.03512.07
5.4.120.0070.03412.03
5.4.110.0040.03712.02
5.4.100.0070.03612.02
5.4.90.0070.03412.02
5.4.80.0100.03412.02
5.4.70.0050.03512.02
5.4.60.0050.03512.02
5.4.50.0060.03512.02
5.4.40.0090.03112.00
5.4.30.0080.03312.00
5.4.20.0050.03612.00
5.4.10.0060.03412.00
5.4.00.0030.03811.49
5.3.290.0060.04312.80
5.3.280.0080.03912.71
5.3.270.0070.04012.72
5.3.260.0060.03912.71
5.3.250.0100.03512.72
5.3.240.0010.04112.72
5.3.230.0090.03712.71
5.3.220.0060.03712.68
5.3.210.0090.04512.68
5.3.200.0040.03812.68
5.3.190.0090.03312.68
5.3.180.0030.03812.67
5.3.170.0070.04012.67
5.3.160.0070.03512.67
5.3.150.0080.03412.68
5.3.140.0050.03612.66
5.3.130.0070.03712.65
5.3.120.0060.03712.65
5.3.110.0040.03912.66
5.3.100.0050.03712.12
5.3.90.0050.03612.10
5.3.80.0060.04212.09
5.3.70.0090.03812.09
5.3.60.0070.03412.07
5.3.50.0060.03612.02
5.3.40.0060.03612.02
5.3.30.0070.03411.98
5.3.20.0090.03511.76
5.3.10.0040.03511.73
5.3.00.0050.03611.71
5.2.170.0040.0319.22
5.2.160.0080.0269.22
5.2.150.0040.0339.22
5.2.140.0050.0379.22
5.2.130.0050.0279.18
5.2.120.0040.0289.18
5.2.110.0060.0269.18
5.2.100.0090.0239.17
5.2.90.0040.0299.17
5.2.80.0060.0309.17
5.2.70.0060.0289.17
5.2.60.0040.0349.13
5.2.50.0050.0289.10
5.2.40.0050.0299.07
5.2.30.0060.0279.05
5.2.20.0040.0309.04
5.2.10.0040.0278.94
5.2.00.0060.0278.80
5.1.60.0050.0238.09
5.1.50.0070.0218.08
5.1.40.0060.0228.07
5.1.30.0050.0248.42
5.1.20.0070.0238.44
5.1.10.0040.0248.16
5.1.00.0030.0268.16
5.0.50.0010.0226.64
5.0.40.0020.0196.50
5.0.30.0050.0286.31
5.0.20.0020.0216.27
5.0.10.0030.0196.26
5.0.00.0040.0296.25
4.4.90.0020.0214.78
4.4.80.0010.0174.76
4.4.70.0050.0144.76
4.4.60.0060.0154.75
4.4.50.0020.0194.77
4.4.40.0040.0344.71
4.4.30.0030.0164.75
4.4.20.0060.0204.84
4.4.10.0050.0184.85
4.4.00.0030.0244.76
4.3.110.0030.0174.67
4.3.100.0000.0194.66
4.3.90.0040.0154.64
4.3.80.0080.0214.59
4.3.70.0030.0204.63
4.3.60.0060.0134.63
4.3.50.0050.0154.63
4.3.40.0010.0284.54
4.3.30.0040.0163.30
4.3.20.0000.0183.28
4.3.10.0060.0123.23
4.3.00.0030.0108.66

preferences:
40.35 ms | 401 KiB | 5 Q