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' => ['double']], 'dbField3' => ['outputField3' => ['double', 'dollars']] ]; public function __construct(array $data) { $this->rawData = $data; $this->mapData(); } /** * @param $value * @return mixed */ private function double($value) { return $value * 2; } /** * @param $value * @return string */ private function dollars($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 getParsedData() { return $this->parsedData; } } // Usually the data comes from the DB so it would be in some kind of Row Set structure $data = ['dbField1' => 1, 'dbField2' => 10, 'dbField3' => 100]; // The data is handed to the Holder which parses it $dm = new DataMapper($data); // The data is parsed so it can be echo json_encode($dm->getParsedData());

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.70.0120.00618.56
8.3.60.0120.00918.56
8.3.50.0140.00421.33
8.3.40.0150.00618.88
8.3.30.0140.00019.18
8.3.20.0000.00820.21
8.3.10.0060.00320.65
8.3.00.0040.00419.38
8.2.190.0110.00718.29
8.2.180.0150.00625.92
8.2.170.0150.00819.04
8.2.160.0080.00822.96
8.2.150.0030.00525.66
8.2.140.0030.00624.66
8.2.130.0050.00326.16
8.2.120.0080.00022.24
8.2.110.0060.00319.33
8.2.100.0050.00918.03
8.2.90.0030.00617.75
8.2.80.0050.00318.78
8.2.70.0000.00817.50
8.2.60.0040.00417.50
8.2.50.0000.00918.07
8.2.40.0040.00418.34
8.2.30.0030.00618.14
8.2.20.0000.00817.64
8.2.10.0070.00018.18
8.2.00.0000.00817.75
8.1.280.0090.00625.92
8.1.270.0000.00923.96
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0170.00024.00
8.1.230.0090.00322.67
8.1.220.0000.00917.74
8.1.210.0040.00418.77
8.1.200.0060.00317.48
8.1.190.0030.00517.23
8.1.180.0000.00818.10
8.1.170.0040.00418.61
8.1.160.0040.00422.13
8.1.150.0000.00718.95
8.1.140.0070.00017.46
8.1.130.0050.00317.84
8.1.120.0040.00417.48
8.1.110.0000.00817.51
8.1.100.0000.00717.39
8.1.90.0000.00717.45
8.1.80.0030.00317.43
8.1.70.0000.00717.46
8.1.60.0060.00617.53
8.1.50.0040.00417.55
8.1.40.0040.00417.51
8.1.30.0030.00517.54
8.1.20.0070.00017.53
8.1.10.0080.00017.54
8.1.00.0000.00717.54
8.0.300.0050.00218.77
8.0.290.0040.00416.75
8.0.280.0050.00318.38
8.0.270.0070.00017.34
8.0.260.0030.00317.21
8.0.250.0030.00317.02
8.0.240.0040.00416.95
8.0.230.0030.00416.98
8.0.220.0000.00716.84
8.0.210.0040.00416.92
8.0.200.0030.00316.85
8.0.190.0030.00616.96
8.0.180.0070.00016.90
8.0.170.0030.00516.95
8.0.160.0000.00716.86
8.0.150.0000.00816.76
8.0.140.0070.00016.89
8.0.130.0040.00413.37
8.0.120.0070.00316.92
8.0.110.0040.00416.73
8.0.100.0080.00016.88
8.0.90.0050.00216.84
8.0.80.0110.00516.95
8.0.70.0040.00416.73
8.0.60.0030.00516.78
8.0.50.0040.00416.86
8.0.30.0120.00817.30
8.0.20.0030.01717.40
8.0.10.0000.00817.09
8.0.00.0100.00816.87
7.4.330.0000.00515.00
7.4.320.0060.00016.64
7.4.300.0000.00716.63
7.4.290.0030.00316.41
7.4.280.0000.00816.60
7.4.270.0000.00716.47
7.4.260.0030.00316.41
7.4.250.0000.00716.48
7.4.240.0000.00716.54
7.4.230.0040.00416.64
7.4.220.0140.00616.44
7.4.210.0090.01216.71
7.4.200.0030.00316.54
7.4.160.0060.00916.36
7.4.150.0080.00917.40
7.4.140.0040.01617.86
7.4.130.0130.00316.50
7.4.120.0080.00816.57
7.4.110.0100.01016.55
7.4.100.0090.00916.33
7.4.90.0060.01316.38
7.4.80.0090.00819.39
7.4.70.0000.01616.69
7.4.60.0130.00716.46
7.4.50.0040.00416.65
7.4.40.0160.00416.57
7.4.30.0080.00916.59
7.4.00.0050.01014.99
7.3.330.0060.00013.35
7.3.320.0000.00513.25
7.3.310.0030.00316.25
7.3.300.0030.00316.38
7.3.290.0040.01216.42
7.3.280.0070.00916.38
7.3.270.0060.01317.40
7.3.260.0140.00416.68
7.3.250.0110.00816.47
7.3.240.0000.01716.64
7.3.230.0060.01016.67
7.3.210.0070.01716.72
7.3.200.0070.01419.39
7.3.190.0030.01716.55
7.3.180.0120.00416.54
7.3.170.0060.01016.31
7.3.160.0130.00316.70
7.3.120.0090.00915.10
7.3.110.0120.00415.00
7.3.100.0070.00714.69
7.3.90.0090.00615.00
7.3.80.0120.00314.56
7.3.70.0040.01414.59
7.3.60.0040.00414.63
7.3.50.0030.00915.04
7.3.40.0110.00414.69
7.3.30.0070.00714.58
7.3.20.0070.00416.63
7.3.10.0040.00916.60
7.3.00.0040.00916.65
7.2.330.0090.00916.83
7.2.320.0160.00916.70
7.2.310.0060.01216.82
7.2.300.0060.01316.48
7.2.290.0090.01216.74
7.2.250.0030.01614.85
7.2.240.0070.01315.00
7.2.230.0000.01115.07
7.2.220.0030.01315.33
7.2.210.0030.00615.26
7.2.200.0060.00314.90
7.2.190.0060.00315.07
7.2.180.0140.00315.20
7.2.170.0100.00314.98
7.2.130.0050.00816.94
7.2.120.0060.01016.92
7.2.110.0080.00416.92
7.2.100.0040.00916.79
7.2.90.0040.01116.93
7.2.80.0040.01216.92
7.2.70.0080.00816.97
7.2.60.0050.00817.01
7.2.50.0090.00816.95
7.2.40.0080.00516.88
7.2.30.0050.01217.01
7.2.20.0060.00816.99
7.2.10.0100.00516.89
7.2.00.0060.00817.37
7.1.330.0070.00715.96
7.1.320.0060.00615.53
7.1.310.0100.00315.98
7.1.300.0070.00715.47
7.1.290.0030.01015.56
7.1.280.0070.00715.52
7.1.270.0000.01415.52
7.1.260.0040.00715.73
7.1.250.0020.01015.77
7.1.240.0110.00415.93
7.1.230.0070.00715.82
7.1.220.0080.00415.77
7.1.210.0060.00615.86
7.1.200.0080.00615.66
7.1.190.0100.00715.47
7.1.180.0060.00615.42
7.1.170.0130.00315.89
7.1.160.0000.00915.77
7.1.150.0030.00615.68
7.1.140.0000.01615.53
7.1.130.0070.00715.71
7.1.120.0040.00715.67
7.1.110.0000.01215.85
7.1.100.0070.00616.76
7.1.90.0070.00315.68
7.1.80.0070.00715.89
7.1.70.0060.00616.61
7.1.60.0110.00817.56
7.1.50.0070.00916.17
7.1.40.0070.00315.67
7.1.30.0040.01015.91
7.1.20.0040.00715.75
7.1.10.0090.00615.93
7.1.00.0080.04019.20
7.0.330.0040.01115.36
7.0.320.0040.00415.30
7.0.310.0130.00315.20
7.0.300.0000.01315.33
7.0.290.0110.00315.36
7.0.280.0000.00915.37
7.0.270.0030.01115.15
7.0.260.0070.01115.27
7.0.250.0070.00714.96
7.0.240.0100.00715.36
7.0.230.0080.00315.18
7.0.220.0090.00615.20
7.0.210.0170.00015.00
7.0.200.0070.00516.04
7.0.190.0070.00715.26
7.0.180.0150.00915.45
7.0.170.0030.01615.19
7.0.160.0030.01015.05
7.0.150.0030.00715.04
7.0.140.0020.04318.71
7.0.130.0120.00315.20
7.0.120.0070.00315.35
7.0.110.0030.01315.33
7.0.100.0150.00015.30
7.0.90.0020.02917.63
7.0.80.0330.02717.64
7.0.70.0250.02117.62
7.0.60.0240.02217.62
7.0.50.0250.04417.93
7.0.40.0100.03516.68
7.0.30.0030.03816.59
7.0.20.0020.02416.78
7.0.10.0050.02216.61
7.0.00.0100.03616.64
5.6.380.0040.00814.48
5.6.370.0060.00614.23
5.6.360.0040.00814.40
5.6.350.0100.00714.30
5.6.340.0030.00614.40
5.6.330.0140.00313.89
5.6.320.0050.00514.11
5.6.310.0030.00714.26
5.6.300.0090.00314.44
5.6.290.0030.01013.94
5.6.280.0030.04217.69
5.6.270.0090.00614.29
5.6.260.0080.00814.16
5.6.250.0060.00914.21
5.6.240.0050.04517.57
5.6.230.0050.03717.40
5.6.220.0100.02517.55
5.6.210.0110.03417.51
5.6.200.0050.05017.65
5.6.190.0020.03017.66
5.6.180.0090.04217.67
5.6.170.0050.02317.80
5.6.160.0060.02117.76
5.6.150.0070.02017.77
5.6.140.0050.04517.73
5.6.130.0050.02717.79
5.6.120.0030.04617.72
5.6.110.0080.04317.54
5.6.100.0040.04117.53
5.6.90.0070.04317.69
5.6.80.0110.02517.39
5.6.70.0070.04217.38
5.6.60.0020.02617.36
5.6.50.0050.04217.27
5.6.40.0040.02517.27
5.6.30.0120.03417.23
5.6.20.0130.03217.32
5.6.10.0080.04017.38
5.6.00.0050.02217.25
5.5.380.0060.03815.84
5.5.370.0070.02715.64
5.5.360.0030.02315.77
5.5.350.0040.02215.86
5.5.340.0020.02215.90
5.5.330.0050.04416.15
5.5.320.0050.04415.89
5.5.310.0090.01516.11
5.5.300.0020.03515.94
5.5.290.0050.03315.75
5.5.280.0000.03216.14
5.5.270.0060.04115.89
5.5.260.0100.04015.94
5.5.250.0050.02715.95
5.5.240.0040.04015.76
5.5.230.0030.02715.60
5.5.220.0080.04215.75
5.5.210.0020.02815.63
5.5.200.0020.03215.62
5.5.190.0070.03915.45
5.5.180.0050.04115.68
5.5.170.0070.00311.20
5.5.160.0080.03515.72
5.5.150.0030.04415.42
5.5.140.0050.04215.80
5.5.130.0020.02515.55
5.5.120.0050.03815.68
5.5.110.0030.04415.67
5.5.100.0070.04515.46
5.5.90.0030.02415.62
5.5.80.0050.03015.63
5.5.70.0050.04515.54
5.5.60.0050.02615.53
5.5.50.0060.01815.53
5.5.40.0030.04215.52
5.5.30.0030.03815.48
5.5.20.0040.02415.70
5.5.10.0080.03715.64
5.5.00.0040.02615.62
5.4.450.0030.04015.29
5.4.440.0090.02015.16
5.4.430.0000.03815.29
5.4.420.0080.02315.28
5.4.410.0070.03714.95
5.4.400.0070.02515.24
5.4.390.0100.03415.01
5.4.380.0070.04214.96
5.4.370.0050.04215.12
5.4.360.0020.04414.98
5.4.350.0070.04215.20
5.4.340.0070.03014.99
5.4.330.0070.00711.48
5.4.320.0030.04415.20
5.4.310.0110.03715.15
5.4.300.0070.02315.10
5.4.290.0080.03815.20
5.4.280.0030.03815.14
5.4.270.0030.03715.03
5.4.260.0110.03515.07
5.4.250.0140.03015.15
5.4.240.0090.03914.92
5.4.230.0130.03515.13
5.4.220.0090.02615.24
5.4.210.0070.03215.03
5.4.200.0050.03515.28
5.4.190.0080.03615.07
5.4.180.0050.04315.08
5.4.170.0060.02015.16
5.4.160.0050.02015.08
5.4.150.0060.01815.18
5.4.140.0030.03313.66
5.4.130.0040.02413.68
5.4.120.0050.02313.55
5.4.110.0030.01913.77
5.4.100.0080.01813.86
5.4.90.0010.02613.83
5.4.80.0030.02313.70
5.4.70.0030.02013.69
5.4.60.0030.01913.82
5.4.50.0030.02013.70
5.4.40.0060.02013.58
5.4.30.0020.02413.51
5.4.20.0050.02013.56
5.4.10.0040.02313.56
5.4.00.0030.02113.49
5.3.290.0050.04012.54
5.3.280.0050.03012.50
5.3.270.0040.03112.58
5.3.260.0020.02312.53
5.3.250.0010.02412.61
5.3.240.0030.02212.52
5.3.230.0070.02012.57
5.3.220.0020.02212.49
5.3.210.0030.02312.51
5.3.200.0050.02212.52
5.3.190.0020.02312.55
5.3.180.0070.02512.46
5.3.170.0050.02012.48
5.3.160.0030.02212.55
5.3.150.0050.02012.54
5.3.140.0060.02112.54
5.3.130.0070.03012.57
5.3.120.0080.02312.55
5.3.110.0100.01512.57
5.3.100.0020.02012.29
5.3.90.0080.01812.28
5.3.80.0030.02112.32
5.3.70.0030.02212.20
5.3.60.0050.03312.24
5.3.50.0050.03312.27
5.3.40.0040.02212.16
5.3.30.0010.01812.14
5.3.20.0060.01612.12
5.3.10.0050.01812.14
5.3.00.0060.01812.07
5.2.170.0030.01710.83
5.2.160.0030.01710.78
5.2.150.0030.01710.88
5.2.140.0000.01710.81
5.2.130.0030.01810.81
5.2.120.0040.01410.72
5.2.110.0050.02410.80
5.2.100.0020.01710.81
5.2.90.0030.01710.83
5.2.80.0050.01210.79
5.2.70.0050.01310.73
5.2.60.0050.02010.79
5.2.50.0050.01610.70
5.2.40.0030.01510.77
5.2.30.0040.01610.74
5.2.20.0030.01710.70
5.2.10.0020.01710.68
5.2.00.0030.01710.60
5.1.60.0010.01810.17
5.1.50.0030.01510.28
5.1.40.0080.01810.26
5.1.30.0080.01710.44
5.1.20.0030.01610.37
5.1.10.0050.01810.32
5.1.00.0040.01210.28
5.0.50.0040.0169.52
5.0.40.0040.0119.47
5.0.30.0000.0319.39
5.0.20.0050.0229.39
5.0.10.0040.0269.27
5.0.00.0030.0279.37
4.4.90.0040.0088.97
4.4.80.0020.0108.97
4.4.70.0010.0108.97
4.4.60.0020.0108.97
4.4.50.0020.0108.97
4.4.40.0040.0118.97
4.4.30.0020.0118.97
4.4.20.0020.0088.97
4.4.10.0020.0098.97
4.4.00.0030.0128.97
4.3.110.0000.0128.97
4.3.100.0030.0178.97
4.3.90.0050.0198.97
4.3.80.0030.0318.97
4.3.70.0100.0138.97
4.3.60.0050.0188.97
4.3.50.0050.0188.97
4.3.40.0080.0238.97
4.3.30.0000.0188.97
4.3.20.0010.0238.97
4.3.10.0000.0228.97
4.3.00.0020.0248.97

preferences:
43.14 ms | 401 KiB | 5 Q