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 var_dump($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.43
8.3.50.0110.00922.01
8.3.40.0040.01118.97
8.3.30.0070.00719.21
8.3.20.0060.00320.34
8.3.10.0050.00320.52
8.3.00.0040.00419.13
8.2.180.0100.01018.41
8.2.170.0150.00022.96
8.2.160.0100.00720.34
8.2.150.0030.00524.18
8.2.140.0070.00724.66
8.2.130.0040.00426.16
8.2.120.0040.00422.13
8.2.110.0110.00019.27
8.2.100.0000.01117.78
8.2.90.0040.00417.91
8.2.80.0000.00817.97
8.2.70.0030.00617.63
8.2.60.0000.00918.03
8.2.50.0060.00318.07
8.2.40.0080.00018.03
8.2.30.0040.00418.09
8.2.20.0050.00317.68
8.2.10.0050.00217.98
8.2.00.0000.00817.79
8.1.280.0000.01425.92
8.1.270.0080.00022.19
8.1.260.0070.00026.35
8.1.250.0050.00328.09
8.1.240.0080.00022.65
8.1.230.0080.00420.87
8.1.220.0040.00417.74
8.1.210.0070.00718.77
8.1.200.0070.00317.36
8.1.190.0080.00017.35
8.1.180.0050.00318.10
8.1.170.0060.00318.61
8.1.160.0000.00721.90
8.1.150.0050.00218.82
8.1.140.0050.00317.38
8.1.130.0070.00017.77
8.1.120.0070.00017.39
8.1.110.0040.00417.47
8.1.100.0030.00517.40
8.1.90.0000.00717.48
8.1.80.0000.00717.47
8.1.70.0000.00817.43
8.1.60.0000.01217.59
8.1.50.0040.00417.44
8.1.40.0000.00917.49
8.1.30.0040.00417.64
8.1.20.0040.00417.55
8.1.10.0000.00817.53
8.1.00.0040.00417.43
8.0.300.0000.00819.98
8.0.290.0040.00416.75
8.0.280.0000.00718.44
8.0.270.0070.00017.21
8.0.260.0070.00017.18
8.0.250.0070.00016.86
8.0.240.0040.00416.97
8.0.230.0000.00816.99
8.0.220.0070.00016.98
8.0.210.0030.00316.84
8.0.200.0070.00016.96
8.0.190.0040.00416.84
8.0.180.0040.00416.92
8.0.170.0040.00416.86
8.0.160.0000.00716.94
8.0.150.0030.00316.92
8.0.140.0040.00416.84
8.0.130.0000.00613.33
8.0.120.0080.00016.84
8.0.110.0080.00016.75
8.0.100.0030.00516.89
8.0.90.0020.00516.72
8.0.80.0060.00916.95
8.0.70.0050.00216.95
8.0.60.0030.00416.85
8.0.50.0000.00716.82
8.0.30.0050.01416.81
8.0.20.0120.00717.40
8.0.10.0000.00817.07
8.0.00.0110.01016.81
7.4.330.0000.00515.20
7.4.320.0030.00316.42
7.4.300.0000.00616.44
7.4.290.0000.00716.65
7.4.280.0000.00716.52
7.4.270.0030.00416.54
7.4.260.0030.00316.50
7.4.250.0030.00616.38
7.4.240.0030.00316.58
7.4.230.0030.00316.51
7.4.220.0090.01316.61
7.4.210.0150.00516.73
7.4.200.0030.00316.42
7.4.160.0040.01216.56
7.4.150.0060.01217.40
7.4.140.0150.00317.86
7.4.130.0070.01116.54
7.4.120.0120.00516.43
7.4.110.0100.00716.51
7.4.100.0080.00816.57
7.4.90.0070.01316.61
7.4.80.0160.00719.39
7.4.70.0060.01216.61
7.4.60.0140.00416.59
7.4.50.0030.00616.54
7.4.40.0070.01416.39
7.4.30.0030.01316.58
7.4.00.0070.01114.91
7.3.330.0030.00313.21
7.3.320.0000.00513.20
7.3.310.0030.00516.38
7.3.300.0000.00616.30
7.3.290.0090.00616.32
7.3.280.0060.01216.34
7.3.270.0000.01717.40
7.3.260.0150.00416.36
7.3.250.0150.00416.38
7.3.240.0090.00916.38
7.3.230.0100.00716.48
7.3.210.0090.00916.46
7.3.200.0100.00719.39
7.3.190.0130.01016.66
7.3.180.0060.00916.67
7.3.170.0100.00616.43
7.3.160.0100.00616.59
7.2.330.0040.01416.85
7.2.320.0120.00616.73
7.2.310.0040.01416.68
7.2.300.0030.01316.92
7.2.290.0100.00916.87
7.2.110.0640.01016.59
7.2.60.0090.00616.77
7.1.200.0040.00415.54
7.1.70.0040.00717.25
7.1.60.0130.01019.32
7.1.50.0100.01016.85
7.1.00.0000.07722.51
7.0.200.0040.00416.84
7.0.140.0000.06721.92
7.0.60.0130.07720.09
7.0.50.0100.07017.90
7.0.40.0030.09020.27
7.0.30.0330.05320.23
7.0.20.0170.04320.16
7.0.10.0070.07020.07
7.0.00.0030.05720.10
5.6.280.0030.07021.13
5.6.210.0070.08020.49
5.6.200.0030.07718.24
5.6.190.0030.09020.63
5.6.180.3200.04320.52
5.6.170.0270.06720.46
5.6.160.0100.08320.54
5.6.150.0100.05318.15
5.6.140.0230.03318.25
5.6.130.0030.04718.18
5.6.120.0070.08321.01
5.6.110.0100.05720.99
5.6.100.0070.08021.01
5.6.90.0070.07021.09
5.6.80.0070.06320.29
5.5.350.0330.07020.42
5.5.340.0030.06017.98
5.5.330.0100.07720.21
5.5.320.0400.05020.35
5.5.310.0430.07320.26
5.5.300.0070.07017.96
5.5.290.0030.07018.10
5.5.280.0170.07020.81
5.5.270.0000.05320.97
5.5.260.0100.06720.77
5.5.250.0100.08720.63
5.5.240.0200.08020.20
5.4.450.0730.05719.48
5.4.440.1000.06719.16
5.4.430.1000.06019.54
5.4.420.0630.00019.68
5.4.410.0630.00019.53
5.4.400.0630.00019.23
5.4.390.0630.00019.13
5.4.380.0830.00019.11
5.4.370.0630.00019.13
5.4.360.0630.00019.21
5.4.350.0670.00019.02
5.4.340.0630.00019.21
5.4.320.0060.03512.51
5.4.310.0060.04712.51
5.4.300.0050.03612.51
5.4.290.0060.04412.51
5.4.280.0080.03612.41
5.4.270.0090.03712.41
5.4.260.0040.04212.41
5.4.250.0070.03812.40
5.4.240.0070.04312.40
5.4.230.0060.04312.40
5.4.220.0050.03612.40
5.4.210.0070.03412.40
5.4.200.0060.03712.40
5.4.190.0060.03512.39
5.4.180.0090.03312.39
5.4.170.0040.03712.41
5.4.160.0050.03712.40
5.4.150.0060.03512.40
5.4.140.0040.04312.08
5.4.130.0050.03712.07
5.4.120.0060.03512.03
5.4.110.0050.03712.02
5.4.100.0030.03812.02
5.4.90.0060.03612.02
5.4.80.0110.03012.02
5.4.70.0060.03912.02
5.4.60.0090.03612.02
5.4.50.0130.03112.02
5.4.40.0060.04012.01
5.4.30.0060.03412.01
5.4.20.0070.03612.00
5.4.10.0060.03312.00
5.4.00.0050.03611.48
5.3.290.0080.03612.80
5.3.280.0050.03712.71
5.3.270.0050.03812.72
5.3.260.0060.03812.72
5.3.250.0050.03712.72
5.3.240.0070.03512.72
5.3.230.0080.03512.71
5.3.220.0120.03112.68
5.3.210.0090.03612.68
5.3.200.0050.03712.68
5.3.190.0050.04712.68
5.3.180.0060.03612.67
5.3.170.0090.03312.67
5.3.160.0060.03612.67
5.3.150.0060.03712.68
5.3.140.0090.03312.66
5.3.130.0060.03812.66
5.3.120.0060.03712.65
5.3.110.0020.04112.66
5.3.100.0070.03412.12
5.3.90.0070.04312.10
5.3.80.0090.03812.09
5.3.70.0030.03812.10
5.3.60.0010.04112.07
5.3.50.0050.03612.02
5.3.40.0060.03612.02
5.3.30.0060.03511.98
5.3.20.0010.04111.76
5.3.10.0110.02911.73
5.3.00.0040.03711.71
5.2.170.0080.0279.22
5.2.160.0090.0289.22
5.2.150.0050.0299.22
5.2.140.0050.0309.22
5.2.130.0050.0289.18
5.2.120.0070.0259.18
5.2.110.0050.0309.18
5.2.100.0040.0289.17
5.2.90.0030.0319.18
5.2.80.0080.0279.17
5.2.70.0020.0339.17
5.2.60.0050.0299.13
5.2.50.0060.0289.10
5.2.40.0050.0289.07
5.2.30.0070.0279.04
5.2.20.0040.0299.04
5.2.10.0020.0308.94
5.2.00.0070.0278.80
5.1.60.0070.0218.09
5.1.50.0030.0268.09
5.1.40.0030.0288.07
5.1.30.0060.0288.41
5.1.20.0060.0288.44
5.1.10.0040.0258.16
5.1.00.0060.0228.16
5.0.50.0040.0196.63
5.0.40.0050.0186.50
5.0.30.0050.0346.31
5.0.20.0010.0236.28
5.0.10.0040.0196.26
5.0.00.0020.0326.25
4.4.90.0040.0144.78
4.4.80.0040.0144.76
4.4.70.0050.0134.75
4.4.60.0020.0164.75
4.4.50.0050.0134.77
4.4.40.0040.0244.71
4.4.30.0030.0154.76
4.4.20.0040.0144.84
4.4.10.0040.0144.84
4.4.00.0010.0264.76
4.3.110.0020.0154.67
4.3.100.0010.0164.67
4.3.90.0030.0144.64
4.3.80.0010.0254.58
4.3.70.0040.0154.63
4.3.60.0010.0164.63
4.3.50.0030.0154.63
4.3.40.0040.0224.54
4.3.30.0020.0163.30
4.3.20.0030.0153.28
4.3.10.0020.0153.23
4.3.00.0170.0207.15

preferences:
43.02 ms | 400 KiB | 5 Q