3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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());
based on mIMQ1

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).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)
7.3.0rc40.0140.00798.97
7.3.0rc30.0720.00616.52
7.3.0beta10.0110.00012.83
7.3.0alpha10.0030.00312.71
7.2.60.0040.01116.70
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