3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('json_encode')) { function json_encode($it) { if (!($assoc = is_object($it)) && !is_array($it)) { return _js_enc_value($it); } $i = 0; $it = (array)$it; if (!$assoc) { foreach ($it as $k => $v) { if ($k !== $i) { $assoc = true; break; } $i++; } } $data = array(); foreach ($it as $k => $v) { $v = _js_enc_value($v); if ($assoc) { $k = _js_enc_value($k); $data[] = $k . ':' . $v; } else { $data[] = $v; } } if ($assoc) { $bl = '{'; $br = '}'; } else { $bl = '['; $br = ']'; } return $bl . implode(',', $data) . $br; } function _js_enc_value($value) { switch (true) { case is_array($value): case is_object($value): return json_encode($value); case is_bool($value): return $value ? 'true' : 'false'; case $value === null: case is_resource($value) && _js_error(): return 'null'; case is_string($value): return '"' . _js_uc_esc($value) . '"'; default: return $value; } } function _js_error() { return trigger_error( 'json_encode(): type is unsupported, encoded as null', E_USER_WARNING ); } function _js_uc_esc($value) { $pattern = "@[\x08-x010\x0c\x0d\\\\\"'/]|([ -!#-&(-.])++@"; return preg_replace_callback($pattern, '_js_uc_esc_cb', $value); } function _js_uc_esc_cb($matches) { switch (true) { case isset($matches[1]): $char = mb_convert_encoding($matches[0], 'UTF-16', 'UTF-8'); $str = ''; $len = strlen($char); for ($i = 0; $i < $len; $i += 2) { $str .= sprintf('\\u%02x%02x', ord($char[$i]), ord($char[$i + 1]) ); } return $str; default: return addcslashes($matches[0], "\f\n\r\t\"'/"); } } } $str = ''; for ($i=0;$i<=32;$i++) { $str .= chr($i); } $str = chr(127); var_dump(json_encode("@'^[]|~"));

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.40.0170.00318.67
8.3.30.0110.01119.22
8.3.20.0110.00320.24
8.3.10.0120.00321.91
8.3.00.0040.00422.32
8.2.170.0070.00722.96
8.2.160.0060.00920.70
8.2.150.0040.01224.18
8.2.140.0040.00424.66
8.2.130.0090.00026.16
8.2.120.0040.00417.63
8.2.110.0060.00322.17
8.2.100.0110.00019.64
8.2.90.0040.00419.25
8.2.80.0000.00817.97
8.2.70.0090.00017.75
8.2.60.0050.00317.91
8.2.50.0030.00618.07
8.2.40.0080.00018.01
8.2.30.0030.00518.30
8.2.20.0050.00217.81
8.2.10.0050.00317.63
8.2.00.0040.00417.63
8.1.270.0090.00022.13
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0040.00424.02
8.1.230.0070.00419.28
8.1.220.0040.00417.74
8.1.210.0030.00618.77
8.1.200.0000.00917.38
8.1.190.0050.00317.40
8.1.180.0000.00818.86
8.1.170.0040.00418.59
8.1.160.0040.00422.00
8.1.150.0050.00318.69
8.1.140.0040.00417.42
8.1.130.0040.00417.96
8.1.120.0000.00717.54
8.1.110.0030.00617.52
8.1.100.0060.00317.55
8.1.90.0000.00717.51
8.1.80.0000.00717.43
8.1.70.0050.00317.48
8.1.60.0080.00017.66
8.1.50.0000.00817.55
8.1.40.0030.00617.51
8.1.30.0000.00817.59
8.1.20.0040.00417.70
8.1.10.0050.00217.44
8.1.00.0080.00017.48
8.0.300.0000.00718.77
8.0.290.0060.00317.30
8.0.280.0070.00018.50
8.0.270.0030.00317.24
8.0.260.0050.00316.90
8.0.250.0070.00317.08
8.0.240.0040.00416.95
8.0.230.0090.00017.04
8.0.220.0030.00317.03
8.0.210.0030.00316.82
8.0.200.0030.00316.89
8.0.190.0040.00316.91
8.0.180.0070.00017.00
8.0.170.0040.00416.89
8.0.160.0000.00816.77
8.0.150.0000.00716.79
8.0.140.0000.00716.81
8.0.130.0030.00313.33
8.0.120.0000.00816.84
8.0.110.0020.00516.96
8.0.100.0000.00716.96
8.0.90.0040.00416.96
8.0.80.0060.01617.01
8.0.70.0000.00816.84
8.0.60.0030.00416.75
8.0.50.0000.00816.95
8.0.30.0130.01216.99
8.0.20.0090.01117.40
8.0.10.0040.00416.97
8.0.00.0100.00816.76
7.4.330.0020.00215.00
7.4.320.0000.00616.60
7.4.300.0000.00616.65
7.4.290.0000.00716.67
7.4.280.0050.00316.52
7.4.270.0070.00016.55
7.4.260.0070.00016.69
7.4.250.0040.00416.48
7.4.240.0050.00216.51
7.4.230.0000.00716.74
7.4.220.0070.01116.52
7.4.210.0090.00716.54
7.4.200.0050.00216.49
7.4.190.0000.00716.69
7.4.160.0060.01016.32
7.4.150.0120.00917.40
7.4.140.0100.00717.86
7.4.130.0140.00716.59
7.4.120.0060.01116.63
7.4.110.0040.01316.49
7.4.100.0090.01516.62
7.4.90.0210.00016.45
7.4.80.0100.00719.39
7.4.70.0090.00616.26
7.4.60.0180.00716.41
7.4.50.0030.00616.45
7.4.40.0000.01122.77
7.4.30.0080.00816.38
7.4.00.0060.00915.12
7.3.330.0000.00613.38
7.3.320.0050.00013.30
7.3.310.0070.00016.32
7.3.300.0000.00716.23
7.3.290.0070.00716.34
7.3.280.0080.00816.34
7.3.270.0040.01317.40
7.3.260.0030.01516.38
7.3.250.0160.00516.74
7.3.240.0200.00016.70
7.3.230.0100.01316.39
7.3.210.0090.00916.57
7.3.200.0090.01219.39
7.3.190.0130.01016.71
7.3.180.0150.00016.67
7.3.170.0070.01516.31
7.3.160.0060.01216.60
7.3.120.0060.00615.02
7.2.330.0070.01016.70
7.2.320.0090.00916.32
7.2.310.0060.01716.56
7.2.300.0030.02016.65
7.2.290.0060.01016.54
7.2.00.0090.00319.37
7.1.100.0300.00617.39
7.1.70.0030.00617.28
7.1.60.0070.01719.82
7.1.50.0110.01417.15
7.1.00.0130.06322.26
7.0.200.0030.00716.53
7.0.140.0030.07322.16
7.0.120.0030.04022.01
7.0.110.0000.04321.90
7.0.100.0030.06722.05
7.0.90.0070.06022.07
7.0.80.0170.02722.06
7.0.70.0070.07021.98
7.0.60.0070.08322.06
7.0.50.0000.06722.04
7.0.40.0030.05320.07
7.0.30.0030.04319.94
7.0.20.0030.05320.07
7.0.10.0000.08020.05
7.0.00.0070.07020.06
5.6.280.0030.07320.88
5.6.270.0000.04020.82
5.6.260.0000.08021.07
5.6.250.0030.06720.81
5.6.240.0000.08021.04
5.6.230.0000.08320.77
5.6.220.0100.07721.01
5.6.210.0070.08020.98
5.6.200.0070.07721.00
5.6.190.0070.07720.96
5.6.180.0100.07020.82
5.6.170.0000.07320.90
5.6.160.0130.06020.80
5.6.150.0030.05020.90
5.6.140.0030.08020.82
5.6.130.0000.06721.05
5.6.120.0070.07320.96
5.6.110.0070.07721.04
5.6.100.0030.09020.79
5.6.90.0000.08321.01
5.6.80.0070.07720.21
5.6.70.0030.08020.09
5.6.60.0030.05720.38
5.6.50.0070.06020.36
5.6.40.0030.06020.25
5.6.30.0000.08020.30
5.6.20.0030.07020.16
5.6.10.0000.04720.39
5.6.00.0030.03720.18
5.5.380.0000.05717.70
5.5.370.0000.07317.61
5.5.360.0030.07317.59
5.5.350.0000.07717.51
5.5.340.0000.08018.09
5.5.330.0070.07317.93
5.5.320.0070.07018.10
5.5.310.0030.06317.95
5.5.300.0070.08018.13
5.5.290.0030.08017.91
5.5.280.0070.07718.05
5.5.270.0000.07718.07
5.5.260.0100.08017.82
5.5.250.0030.07018.04
5.5.240.0100.06317.46
5.5.230.0030.07717.47
5.5.220.0070.04017.30
5.5.210.0070.04317.43
5.5.200.0070.04317.27
5.5.190.0070.04317.48
5.5.180.0030.03717.31
5.5.160.0000.04717.59
5.5.150.0070.06317.28
5.5.140.0070.04717.47
5.5.130.0100.07017.42
5.5.120.0070.07317.48
5.5.110.0030.08317.30
5.5.100.0100.07017.33
5.5.90.0070.07017.39
5.5.80.0070.07317.38
5.5.70.0030.07017.33
5.5.60.0030.07317.47
5.5.50.0030.06717.47
5.5.40.0030.07717.36
5.5.30.0070.07717.34
5.5.20.0000.08017.31
5.5.10.0030.07317.20
5.5.00.0100.06717.29
5.4.450.0030.08319.25
5.4.440.0030.08019.41
5.4.430.0030.07319.45
5.4.420.0030.08319.31
5.4.410.0030.06719.35
5.4.400.0100.06719.16
5.4.390.0030.05019.11
5.4.380.0000.04319.14
5.4.370.0030.07018.86
5.4.360.0100.06719.12
5.4.350.0030.05319.13
5.4.340.0000.06719.16
5.4.320.0000.04318.90
5.4.310.0030.08019.25
5.4.300.0000.07319.14
5.4.290.0000.08019.11
5.4.280.0030.07319.24
5.4.270.0100.06718.98
5.4.260.0130.06719.27
5.4.250.0030.07319.13
5.4.240.0100.06719.14
5.4.230.0000.05019.00
5.4.220.0030.07319.10
5.4.210.0030.07319.08
5.4.200.0070.04318.94
5.4.190.0170.07719.23
5.4.180.0100.06719.02
5.4.170.0070.07319.09
5.4.160.0070.06718.89
5.4.150.0100.07319.12
5.4.140.0100.06316.52
5.4.130.0070.07016.49
5.4.120.0070.03316.54
5.4.110.0000.07716.25
5.4.100.0000.03716.50
5.4.90.0000.05716.39
5.4.80.0070.06316.25
5.4.70.0030.07016.49
5.4.60.0070.07016.29
5.4.50.0070.07316.34
5.4.40.0000.07716.33
5.4.30.0170.06316.37
5.4.20.0030.07316.37
5.4.10.0070.07016.43
5.4.00.0030.06716.01
5.3.290.0000.04014.78
5.3.280.0030.05014.76
5.3.270.0070.07314.77
5.3.260.0100.07714.59
5.3.250.0030.06714.64
5.3.240.0100.07014.64
5.3.230.0100.04014.77
5.3.220.0000.06714.71
5.3.210.0000.07314.55
5.3.200.0000.04014.69
5.3.190.0070.07714.74
5.3.180.0030.06314.83
5.3.170.0070.06714.58
5.3.160.0070.07014.81
5.3.150.0000.07714.54
5.3.140.0100.07014.57
5.3.130.0130.07014.70
5.3.120.0030.07014.43
5.3.110.0030.07014.71
5.3.100.0070.03014.07
5.3.90.0070.07314.14
5.3.80.0030.08014.05
5.3.70.0000.03714.19
5.3.60.0000.06314.12
5.3.50.0130.05314.13
5.3.40.0130.06313.85
5.3.30.0130.04013.97
5.3.20.0070.07013.75
5.3.10.0000.04013.70
5.3.00.0070.07313.64
5.2.170.0000.03011.40
5.2.160.0100.04311.19
5.2.150.0030.06011.19
5.2.140.0000.03011.16
5.2.130.0100.05311.16
5.2.120.0070.05711.13
5.2.110.0070.05711.15
5.2.100.0070.05711.13
5.2.90.0070.05711.15
5.2.80.0100.05711.14
5.2.70.0000.07011.27
5.2.60.0030.06311.08
5.2.50.0070.05311.03
5.2.40.0030.05711.11
5.2.30.0070.05010.97
5.2.20.0100.05311.05
5.2.10.0070.05710.88
5.2.00.0070.06010.77
5.1.60.0030.05310.00
5.1.50.0030.02310.01
5.1.40.0030.04710.02
5.1.30.0000.03310.44
5.1.20.0030.02310.33
5.1.10.0000.02710.18
5.1.00.0000.03310.16
5.0.50.0070.0209.79
5.0.40.0000.0279.79
5.0.30.0000.0309.79
5.0.20.0000.0179.79
5.0.10.0000.0279.79
5.0.00.0000.0639.79
4.4.90.0000.0379.79
4.4.80.0030.0309.79
4.4.70.0000.0379.79
4.4.60.0030.0339.79
4.4.50.0000.0379.79
4.4.40.0000.0509.79
4.4.30.0030.0179.79
4.4.20.0000.0179.79
4.4.10.0030.0139.79
4.4.00.0000.0279.79
4.3.110.0000.0179.79
4.3.100.0000.0139.79
4.3.90.0000.0139.79
4.3.80.0030.0239.79
4.3.70.0000.0179.79
4.3.60.0000.0179.79
4.3.50.0000.0179.79
4.3.40.0000.0439.79
4.3.30.0000.0179.79
4.3.20.0100.0209.79
4.3.10.0000.0179.79
4.3.00.0030.0139.79

preferences:
40.42 ms | 400 KiB | 5 Q