3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A implements JsonSerializable { protected $a = array(); public function __construct() { $this->a = array( new B, new B ); } public function jsonSerialize() { return $this->a; } } class B implements JsonSerializable { protected $b = array( 'foo' => 'bar' ); public function jsonSerialize() { return $this->b; } } $foo = new A(); $json = json_encode($foo); var_dump($json); class Example implements JsonSerializable { private $_data = array(); public function getData($key = null) { if (is_null($key)) { return $this->_data; } if (array_key_exists($key, $this->_data)) { return $this->_data[$key]; } return null; } public function setData($key, $value = null) { if (is_array($key)) { if (!is_null($value)) { throw new Exception('When setting data in bulk, the value argument must be null'); } $this->_data = $key; return $this; } $this->_data[(string)$key] = $value; return $this; } public function jsonSerialize() { return $this->_data; } } $example = new Example(); $example->setData(array( 'first' => 1, 'second' => 2, ))->setData('third', 3); var_dump(json_encode($example)); $example2 = new Example(); $example3 = new Example(); $example2->setData(array( 'banana' => 'yellow', )); $example3->setData(array( 'apple' => 'red', )); $arr = array( $example, $example2, $example3, ); var_dump(json_encode($arr));

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.0160.00616.86
8.3.50.0120.01121.15
8.3.40.0140.00418.88
8.3.30.0130.00919.17
8.3.20.0080.00020.36
8.3.10.0000.00821.87
8.3.00.0080.00019.56
8.2.180.0130.00616.63
8.2.170.0130.00719.07
8.2.160.0150.00622.96
8.2.150.0030.00724.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0000.00819.66
8.2.110.0000.00919.24
8.2.100.0120.00017.78
8.2.90.0040.00417.75
8.2.80.0060.00318.73
8.2.70.0050.00317.75
8.2.60.0050.00317.38
8.2.50.0060.00317.75
8.2.40.0030.00518.16
8.2.30.0050.00318.23
8.2.20.0000.01117.68
8.2.10.0000.00718.08
8.2.00.0000.00718.16
8.1.280.0040.01125.92
8.1.270.0040.00420.38
8.1.260.0060.00326.35
8.1.250.0000.00728.09
8.1.240.0130.00719.46
8.1.230.0050.00522.82
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0030.00617.60
8.1.190.0100.00017.38
8.1.180.0120.00018.10
8.1.170.0040.00718.68
8.1.160.0000.00818.91
8.1.150.0060.00318.55
8.1.140.0030.00517.43
8.1.130.0040.00417.93
8.1.120.0040.00417.55
8.1.110.0040.00417.55
8.1.100.0040.00417.51
8.1.90.0000.00717.53
8.1.80.0050.00317.50
8.1.70.0000.00717.52
8.1.60.0060.00317.60
8.1.50.0000.00817.44
8.1.40.0030.00517.56
8.1.30.0040.00417.65
8.1.20.0000.00817.68
8.1.10.0030.00517.64
8.1.00.0050.00317.58
8.0.300.0000.00818.77
8.0.290.0000.00816.63
8.0.280.0000.00718.41
8.0.270.0040.00417.32
8.0.260.0030.00317.32
8.0.250.0070.00017.00
8.0.240.0070.00016.94
8.0.230.0030.00316.85
8.0.220.0000.00716.83
8.0.210.0000.00716.99
8.0.200.0000.00817.00
8.0.190.0080.00016.96
8.0.180.0000.00716.98
8.0.170.0040.00416.95
8.0.160.0040.00417.02
8.0.150.0040.00416.87
8.0.140.0000.00816.85
8.0.130.0090.00013.42
8.0.120.0040.00416.79
8.0.110.0000.00816.90
8.0.100.0000.00716.94
8.0.90.0080.00016.96
8.0.80.0100.00716.98
8.0.70.0050.00316.86
8.0.60.0000.00816.90
8.0.50.0040.00416.96
8.0.30.0080.01316.91
8.0.20.0120.01317.40
8.0.10.0000.00816.95
8.0.00.0080.00916.93
7.4.330.0000.00815.03
7.4.320.0060.00016.70
7.4.300.0000.00616.55
7.4.290.0000.00716.66
7.4.280.0030.00516.47
7.4.270.0000.00716.64
7.4.260.0030.00316.62
7.4.250.0030.00516.67
7.4.240.0070.00016.54
7.4.230.0000.00716.49
7.4.220.0130.01316.62
7.4.210.0170.00316.70
7.4.200.0030.00316.47
7.4.160.0070.00716.54
7.4.150.0060.01117.40
7.4.140.0150.00617.86
7.4.130.0120.00816.64
7.4.120.0090.00916.51
7.4.110.0060.01616.45
7.4.100.0040.01516.52
7.4.90.0030.01416.56
7.4.80.0130.01019.39
7.4.70.0120.01216.43
7.4.60.0100.00616.73
7.4.50.0000.00716.47
7.4.40.0140.00616.73
7.4.30.0040.01316.51
7.4.00.0080.00814.99
7.3.330.0000.00513.42
7.3.320.0060.00013.25
7.3.310.0050.00316.30
7.3.300.0000.00716.33
7.3.290.0100.00616.35
7.3.280.0070.01016.40
7.3.270.0090.00817.40
7.3.260.0140.00716.57
7.3.250.0080.01016.47
7.3.240.0120.00916.41
7.3.230.0170.00616.55
7.3.210.0120.00616.71
7.3.200.0100.00716.72
7.3.190.0060.00916.63
7.3.180.0110.00416.33
7.3.170.0000.01816.55
7.3.160.0060.01016.38
7.3.120.0120.00214.77
7.3.110.0090.00614.90
7.3.100.0050.01114.89
7.3.90.0120.00414.67
7.3.80.0070.00914.83
7.3.70.0080.00714.95
7.3.60.0030.00914.71
7.3.50.0070.00414.83
7.3.40.0050.01014.86
7.3.30.0070.00714.78
7.3.20.0080.00916.85
7.3.10.0050.00816.72
7.3.00.0090.00916.70
7.2.330.0040.01416.79
7.2.320.0150.00616.55
7.2.310.0110.01616.91
7.2.300.0050.01116.76
7.2.290.0070.01016.56
7.2.250.0030.01314.82
7.2.240.0030.01115.18
7.2.230.0080.00815.08
7.2.220.0070.00715.01
7.2.210.0110.00614.86
7.2.200.0070.00615.17
7.2.190.0040.01015.16
7.2.180.0070.00815.07
7.2.170.0050.00915.10
7.2.160.0070.00715.06
7.2.150.0030.00616.89
7.2.140.0200.00317.00
7.2.130.0040.01116.85
7.2.120.0070.00717.11
7.2.110.0180.01116.89
7.2.100.0130.01716.98
7.2.90.0080.01716.75
7.2.80.0210.01417.03
7.2.70.0180.01116.70
7.2.60.0050.00816.81
7.2.50.0000.01417.09
7.2.40.0100.00717.11
7.2.30.0060.00917.11
7.2.20.0070.00716.89
7.2.10.0000.01516.96
7.2.00.0100.00418.16
7.1.330.0070.00515.82
7.1.320.0060.00615.87
7.1.310.0090.00415.70
7.1.300.0050.01015.80
7.1.290.0070.00815.75
7.1.280.0050.00915.71
7.1.270.0050.00615.87
7.1.260.0050.00915.83
7.1.250.0030.01015.64
7.1.200.0060.00615.79
7.1.100.0090.00018.10
7.1.70.0040.01117.02
7.1.60.0070.01719.86
7.1.50.0150.00616.75
7.1.00.0070.07322.35
7.0.200.0030.00616.85
7.0.90.0600.05320.03
7.0.80.0470.04319.90
7.0.70.0370.08319.98
7.0.60.0500.06320.09
7.0.50.0600.08320.27
7.0.40.0100.06720.03
7.0.30.0130.04720.00
7.0.20.0070.08320.13
7.0.10.0070.06320.16
7.0.00.0000.07720.02
5.6.280.0030.07320.84
5.6.240.0070.04020.55
5.6.230.0100.07020.60
5.6.220.0030.08320.63
5.6.210.0070.08020.70
5.6.200.0000.06721.10
5.6.190.0070.08021.05
5.6.180.0170.07021.05
5.6.170.0030.08321.06
5.6.160.0130.07321.12
5.6.150.0100.07720.99
5.6.140.0100.07721.18
5.6.130.0100.06721.10
5.6.120.0030.05721.11
5.6.110.0100.07721.01
5.6.100.0070.08721.03
5.6.90.0070.04320.93
5.6.80.0070.07720.53
5.6.70.0100.07720.34
5.6.60.0000.05020.34
5.6.50.0100.03720.41
5.6.40.0030.04020.36
5.6.30.0030.04020.40
5.6.20.0070.03720.30
5.6.10.0070.03720.39
5.6.00.0030.05320.42
5.5.380.0070.06720.47
5.5.370.0030.04720.36
5.5.360.0070.04320.36
5.5.350.0030.08020.38
5.5.340.0070.05320.85
5.5.330.0030.06320.88
5.5.320.0070.08720.84
5.5.310.0030.05720.90
5.5.300.0070.07320.89
5.5.290.0100.08020.77
5.5.280.0100.06720.94
5.5.270.0070.05720.87
5.5.260.0100.07720.87
5.5.250.0130.06720.71
5.5.240.0130.04320.20
5.5.230.0100.07020.22
5.5.220.0070.04320.22
5.5.210.0100.04720.17
5.5.200.0070.04320.20
5.5.190.0030.04020.16
5.5.180.0030.04720.23
5.5.160.0030.04020.01
5.5.150.0070.03720.12
5.5.140.0100.03320.19
5.5.130.0030.04020.16
5.5.120.0000.04020.27
5.5.110.0070.07720.00
5.5.100.0130.03320.07
5.5.90.0130.04320.11
5.5.80.0070.03320.09
5.5.70.0030.04020.07
5.5.60.0070.06720.13
5.5.50.0030.05320.02
5.5.40.0030.05320.14
5.5.30.0000.04019.95
5.5.20.0000.04720.07
5.5.10.0070.03320.04
5.5.00.0100.03320.13
5.4.450.0070.05019.49
5.4.440.0070.08319.17
5.4.430.0000.05019.34
5.4.420.0030.05019.44
5.4.410.0170.06719.43
5.4.400.0070.08018.85
5.4.390.0070.07718.94
5.4.380.0130.06019.12
5.4.370.0030.05019.03
5.4.360.0070.04019.16
5.4.350.0000.03719.04
5.4.340.0000.04319.12
5.4.320.0070.03318.95
5.4.310.0000.04019.03
5.4.300.0030.04019.20
5.4.290.0070.03718.87
5.4.280.0070.03319.04
5.4.270.0030.04018.87
5.4.260.0030.04019.12
5.4.250.0070.03318.90
5.4.240.0030.06718.89
5.4.230.0000.04018.87
5.4.220.0030.04019.20
5.4.210.0000.04019.04
5.4.200.0000.04018.91
5.4.190.0000.04718.93
5.4.180.0070.03319.22
5.4.170.0070.03019.02
5.4.160.0030.04019.21
5.4.150.0070.03319.00
5.4.140.0070.03316.47
5.4.130.0070.03016.50
5.4.120.0000.03716.49
5.4.110.0030.03716.48
5.4.100.0030.03716.54
5.4.90.0000.03716.54
5.4.80.0030.03716.43
5.4.70.0070.03316.49
5.4.60.0070.03016.40
5.4.50.0000.03716.45
5.4.40.0030.07316.51
5.4.30.0030.07016.33
5.4.20.0000.03316.32
5.4.10.0170.06316.31
5.4.00.0030.07315.81
5.3.290.0000.04714.65
5.3.280.0070.03314.61
5.3.270.0070.05314.61
5.3.260.0000.04014.63
5.3.250.0030.04314.55
5.3.240.0030.04014.69
5.3.230.0070.03714.64
5.3.220.0030.03014.54
5.3.210.0070.03314.52
5.3.200.0030.04314.73
5.3.190.0030.06314.52
5.3.180.0030.03714.70
5.3.170.0030.03714.65
5.3.160.0030.03714.59
5.3.150.0070.03314.71
5.3.140.0030.03714.64
5.3.130.0030.04314.50
5.3.120.0070.03014.57
5.3.110.0070.07314.62
5.3.100.0200.07014.02
5.3.90.0070.05714.09
5.3.80.0000.04314.09
5.3.70.0070.06313.97
5.3.60.0000.08314.16
5.3.50.0070.07314.09
5.3.40.0100.06314.05
5.3.30.0100.05713.96
5.3.20.0070.05013.73
5.3.10.0000.06713.56
5.3.00.0000.07713.78
5.2.170.0130.05311.15
5.2.160.0130.05011.16
5.2.150.0070.06311.19
5.2.140.0030.05311.14
5.2.130.0030.03311.26
5.2.120.0070.03311.23
5.2.110.0100.05711.16
5.2.100.0230.04310.98
5.2.90.0230.04711.15
5.2.80.0070.05311.04
5.2.70.0030.03311.13
5.2.60.0100.03011.13
5.2.50.0000.03310.95
5.2.40.0030.03011.08
5.2.30.0000.06311.02
5.2.20.0100.03711.00
5.2.10.0070.05010.93
5.2.00.0070.03310.79
5.1.60.0030.05710.13
5.1.50.0030.05710.02
5.1.40.0070.03710.04
5.1.30.0070.05310.28
5.1.20.0030.04710.43
5.1.10.0100.05010.15
5.1.00.0030.05710.18
5.0.50.0000.0278.67
5.0.40.0030.0208.52
5.0.30.0000.0338.27
5.0.20.0070.0438.32
5.0.10.0000.0308.24
5.0.00.0070.0538.30
4.4.90.0030.0337.62
4.4.80.0000.0307.62
4.4.70.0070.0307.62
4.4.60.0070.0277.62
4.4.50.0070.0337.62
4.4.40.0000.0577.62
4.4.30.0030.0307.62
4.4.20.0000.0377.62
4.4.10.0030.0237.62
4.4.00.0000.0507.62
4.3.110.0000.0207.62
4.3.100.0070.0137.62
4.3.90.0030.0277.62
4.3.80.0070.0477.62
4.3.70.0000.0377.62
4.3.60.0000.0337.62
4.3.50.0000.0377.62
4.3.40.0100.0437.62
4.3.30.0030.0337.62
4.3.20.0070.0307.62
4.3.10.0030.0177.62
4.3.00.0000.0237.62

preferences:
58.67 ms | 401 KiB | 5 Q