3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('json_encode')) { function json_encode($it) { $tmp = $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); if ($k === 'null') { $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 !_js_check_utf8($value): case $value === null: case is_resource($value): return 'null'; case is_bool($value): return $value ? 'true' : 'false'; case is_string($value): return _js_uc_esc($value); default: return $value; } } function _js_uc_esc($value) { $pattern = "@[\x08-\x10\x0c\x0d\\\\\"/]|([^\x08-\x10\x0c\x0d\x32-\x7f\\\\\"/])++@"; 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], "\x08\x09\x10\x0c\x0d\\\"/"); } } function _js_check_utf8($str) { $len = strlen($str); for($i = 0; $i < $len; $i++){ $c = ord($str[$i]); if ($c > 128) { if ($c > 247) { return false; } elseif ($c > 239) { $bytes = 4; } elseif ($c > 223) { $bytes = 3; } elseif ($c > 191) { $bytes = 2; } else { return false; } if (($i + $bytes) > $len) { return false; } while ($bytes > 1) { $i++; $b = ord($str[$i]); if ($b < 128 || $b > 191) { return false; } $bytes--; } } } return true; } } $str = ''; for ($i=0;$i<=300;$i++) { $str .= chr($i); } $str .= chr(127); var_dump(json_encode(array(null => $str)));

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.0090.00616.50
8.3.50.0080.00817.44
8.3.40.0120.00318.97
8.3.30.0090.00618.84
8.3.20.0040.00418.74
8.3.10.0040.00420.39
8.3.00.0030.00617.63
8.2.180.0120.00916.50
8.2.170.0070.01122.96
8.2.160.0070.00719.51
8.2.150.0000.00924.18
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0040.00420.07
8.2.110.0040.00721.11
8.2.100.0060.00617.91
8.2.90.0040.00419.35
8.2.80.0040.00417.97
8.2.70.0030.00617.75
8.2.60.0060.00617.92
8.2.50.0040.00418.07
8.2.40.0030.00520.01
8.2.30.0040.00418.25
8.2.20.0000.00817.72
8.2.10.0040.00417.74
8.2.00.0030.00517.84
8.1.280.0120.00625.92
8.1.270.0000.00824.66
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0160.00721.42
8.1.230.0040.00717.42
8.1.220.0040.00417.76
8.1.210.0060.00318.77
8.1.200.0000.00917.35
8.1.190.0030.00617.23
8.1.180.0040.00418.10
8.1.170.0000.00918.96
8.1.160.0000.00818.98
8.1.150.0070.00218.67
8.1.140.0060.00317.50
8.1.130.0030.00317.88
8.1.120.0040.00417.45
8.1.110.0040.00417.39
8.1.100.0080.00017.47
8.1.90.0070.00017.49
8.1.80.0040.00417.46
8.1.70.0030.00317.48
8.1.60.0000.00717.55
8.1.50.0040.00417.42
8.1.40.0030.00617.43
8.1.30.0040.00417.57
8.1.20.0090.00017.55
8.1.10.0030.00617.46
8.1.00.0000.00817.46
8.0.300.0030.00618.77
8.0.290.0050.00316.88
8.0.280.0020.00518.50
8.0.270.0000.00717.27
8.0.260.0000.00716.87
8.0.250.0040.00416.89
8.0.240.0040.00416.99
8.0.230.0040.00417.00
8.0.220.0070.00016.98
8.0.210.0000.00716.93
8.0.200.0040.00417.02
8.0.190.0030.00517.00
8.0.180.0040.00416.85
8.0.170.0040.00417.00
8.0.160.0080.00016.99
8.0.150.0000.00816.92
8.0.140.0040.00416.95
8.0.130.0000.00513.32
8.0.120.0050.00316.88
8.0.110.0040.00417.00
8.0.100.0030.00316.79
8.0.90.0080.00016.85
8.0.80.0100.01016.98
8.0.70.0040.00416.96
8.0.60.0050.00216.88
8.0.50.0080.00017.06
8.0.30.0080.01517.07
8.0.20.0090.01117.28
8.0.10.0050.00316.94
8.0.00.0140.00316.78
7.4.330.0000.00513.07
7.4.320.0060.00016.47
7.4.300.0030.00316.57
7.4.290.0000.00816.66
7.4.280.0030.00616.61
7.4.270.0000.00716.48
7.4.260.0050.00013.26
7.4.250.0040.00416.56
7.4.240.0040.00416.61
7.4.230.0080.00016.78
7.4.220.0080.00816.46
7.4.210.0070.01016.60
7.4.200.0040.00416.69
7.4.190.0000.00716.38
7.4.160.0220.00016.61
7.4.150.0150.00717.07
7.4.140.0190.01317.24
7.4.130.0040.01316.55
7.4.120.0090.00816.53
7.4.110.0100.01016.58
7.4.100.0070.01116.42
7.4.90.0120.00416.54
7.4.80.0070.01118.63
7.4.70.0100.00716.41
7.4.60.0030.01416.64
7.4.50.0000.00818.82
7.4.40.0040.00721.69
7.4.30.0060.01016.54
7.4.00.0120.00614.78
7.3.330.0040.00413.32
7.3.320.0000.00513.41
7.3.310.0040.00416.25
7.3.300.0080.00016.48
7.3.290.0030.01216.38
7.3.280.0080.00716.42
7.3.270.0130.01017.07
7.3.260.0120.01018.24
7.3.250.0060.01416.44
7.3.240.0040.01316.47
7.3.230.0100.00616.65
7.3.210.0060.01116.55
7.3.200.0070.01719.39
7.3.190.0140.00616.66
7.3.180.0090.00816.55
7.3.170.0100.00616.79
7.3.160.0070.00716.39
7.3.120.0020.01414.94
7.3.110.0090.00814.96
7.3.100.0030.01214.92
7.3.90.0080.00815.13
7.3.80.0050.00714.70
7.3.70.0120.00314.88
7.3.60.0090.00715.00
7.3.50.0060.00714.85
7.3.40.0050.00914.97
7.3.30.0070.01014.79
7.3.20.0050.01116.75
7.3.10.0040.00916.53
7.3.00.0050.00816.81
7.2.330.0230.00016.46
7.2.320.0160.00616.80
7.2.310.0150.00316.75
7.2.300.0130.00316.60
7.2.290.0040.01316.40
7.2.250.0040.01514.83
7.2.240.0080.00814.87
7.2.230.0080.00715.26
7.2.220.0090.00715.10
7.2.210.0100.00515.23
7.2.200.0090.00914.93
7.2.190.0070.00714.95
7.2.180.0050.00914.89
7.2.170.0030.01314.92
7.2.160.0060.00914.78
7.2.150.0100.00616.83
7.2.140.0040.01117.06
7.2.130.0040.00716.90
7.2.120.0050.00817.02
7.2.110.0110.00516.88
7.2.100.0030.01016.65
7.2.90.0050.00916.82
7.2.80.0050.01016.67
7.2.70.0070.00516.85
7.2.60.0090.00516.85
7.2.50.0080.00916.93
7.2.40.0060.00616.99
7.2.30.0040.00616.87
7.2.20.0060.00817.04
7.2.10.0120.00116.88
7.2.00.0090.00617.69
7.1.330.0050.00815.78
7.1.320.0080.00715.84
7.1.310.0060.00515.82
7.1.300.0070.00415.66
7.1.290.0050.00615.67
7.1.280.0050.00715.65
7.1.270.0060.00715.78
7.1.260.0030.00915.89
7.1.250.0050.00815.77
7.1.100.0080.00418.34
7.1.70.0030.00816.86
7.1.60.0070.01419.40
7.1.50.0180.01834.88
7.1.00.0030.06722.43
7.0.200.0100.00316.80
7.0.140.0030.06721.95
7.0.120.0000.03322.03
7.0.90.0070.04719.86
7.0.80.0500.07019.91
7.0.70.0100.06020.00
7.0.60.0100.08019.96
7.0.50.0330.08020.38
7.0.40.0170.07320.05
7.0.30.0030.07320.14
7.0.20.0070.08020.13
7.0.10.0070.07320.14
7.0.00.0070.07320.17
5.6.280.0070.06721.13
5.6.240.0100.06320.65
5.6.230.0000.08320.46
5.6.220.0030.08720.58
5.6.210.0070.08020.52
5.6.200.0070.08721.03
5.6.190.0070.08321.11
5.6.180.0100.03721.06
5.6.170.0130.07720.97
5.6.160.0100.07321.06
5.6.150.0130.06321.16
5.6.140.0100.08321.10
5.6.130.0030.09021.05
5.6.120.0100.07321.06
5.6.110.0070.06020.96
5.6.100.0170.07321.01
5.6.90.0200.07721.04
5.6.80.0100.07020.34
5.6.70.0200.07320.42
5.6.60.0130.08320.53
5.6.50.0070.08020.51
5.6.40.0030.07720.38
5.6.30.0130.07320.39
5.6.20.0070.07720.42
5.6.10.0000.09020.32
5.6.00.0030.05020.50
5.5.380.0030.05020.38
5.5.370.0070.04320.39
5.5.360.0070.08320.38
5.5.350.0070.06720.39
5.5.340.0030.09020.91
5.5.330.0070.08320.85
5.5.320.0030.09320.75
5.5.310.0030.05320.88
5.5.300.0070.09020.75
5.5.290.0070.08020.88
5.5.280.0070.09020.95
5.5.270.0030.08720.91
5.5.260.0030.08020.93
5.5.250.0030.05020.63
5.5.240.0100.08020.30
5.5.230.0170.08020.28
5.5.220.0170.03320.32
5.5.210.0170.06320.19
5.5.200.0100.08320.17
5.5.190.0130.07720.13
5.5.180.0100.04720.14
5.5.160.0100.04020.01
5.5.150.0030.08720.29
5.5.140.0100.08020.14
5.5.130.0070.07720.23
5.5.120.0130.07020.29
5.5.110.0200.05320.28
5.5.100.0170.06720.07
5.5.90.0100.08020.09
5.5.80.0070.06320.18
5.5.70.0100.08320.02
5.5.60.0100.07720.10
5.5.50.0070.06020.18
5.5.40.0070.07720.11
5.5.30.0030.06320.02
5.5.20.0070.07320.15
5.5.10.0100.07320.05
5.5.00.0100.04719.99
5.4.450.0030.08319.38
5.4.440.0030.08719.23
5.4.430.0100.07719.32
5.4.420.0100.07019.17
5.4.410.0100.07319.32
5.4.400.0030.05319.04
5.4.390.0200.04719.18
5.4.380.0100.06019.04
5.4.370.0100.07319.03
5.4.360.0330.05019.13
5.4.350.0170.06719.22
5.4.340.0030.04719.13
5.4.320.0170.07018.88
5.4.310.0100.07719.25
5.4.300.0030.04719.06
5.4.290.0070.07718.90
5.4.280.0000.06719.15
5.4.270.0030.04319.05
5.4.260.0200.04319.04
5.4.250.0230.05318.93
5.4.240.0100.07319.11
5.4.230.0100.08019.04
5.4.220.0130.06718.89
5.4.210.0070.04319.04
5.4.200.0000.07719.09
5.4.190.0100.06719.11
5.4.180.0100.06719.24
5.4.170.0100.06319.12
5.4.160.0030.09318.83
5.4.150.0070.04319.11
5.4.140.0030.05716.45
5.4.130.0000.06016.46
5.4.120.0030.04016.34
5.4.110.0130.06716.56
5.4.100.0070.05316.52
5.4.90.0100.06016.50
5.4.80.0070.07316.54
5.4.70.0070.06716.39
5.4.60.0070.03716.36
5.4.50.0070.07316.30
5.4.40.0030.07316.46
5.4.30.0100.06316.43
5.4.20.0030.04016.36
5.4.10.0100.06316.33
5.4.00.0030.07715.80
5.3.290.0100.07314.79
5.3.280.0170.06714.64
5.3.270.0100.06014.65
5.3.260.0070.07314.61
5.3.250.0070.07014.63
5.3.240.0030.08014.65
5.3.230.0030.06714.67
5.3.220.0100.07314.59
5.3.210.0000.05714.66
5.3.200.0070.06314.70
5.3.190.0070.04014.55
5.3.180.0030.07014.52
5.3.170.0030.04714.71
5.3.160.0070.04014.65
5.3.150.0000.07314.64
5.3.140.0130.03314.65
5.3.130.0030.05714.64
5.3.120.0070.08314.72
5.3.110.0000.04714.58
5.3.100.0070.07314.13
5.3.90.0070.07314.09
5.3.80.0070.07714.17
5.3.70.0170.05713.98
5.3.60.0030.07313.95
5.3.50.0070.06714.04
5.3.40.0100.07013.96
5.3.30.0070.07714.08
5.3.20.0130.06313.64
5.3.10.0030.07313.81
5.3.00.0070.07313.59
5.2.170.0100.05011.08
5.2.160.0030.06311.09
5.2.150.0000.04311.27
5.2.140.0000.04011.27
5.2.130.0000.06311.07
5.2.120.0070.03311.03
5.2.110.0070.06011.19
5.2.100.0070.06011.27
5.2.90.0030.07311.19
5.2.80.0000.06711.22
5.2.70.0000.06311.27
5.2.60.0070.03711.20
5.2.50.0000.03011.11
5.2.40.0030.06311.12
5.2.30.0000.06710.94
5.2.20.0000.05711.01
5.2.10.0130.04311.00
5.2.00.0000.04010.85
5.1.60.0130.04310.58
5.1.50.0030.05310.58
5.1.40.0100.05010.58
5.1.30.0030.05710.58
5.1.20.0100.05310.58
5.1.10.0030.05310.58
5.1.00.0070.03310.58
5.0.50.0000.04310.58
5.0.40.0070.03710.58
5.0.30.0070.05010.58
5.0.20.0070.03010.58
5.0.10.0000.03710.58
5.0.00.0070.06010.58
4.4.90.0000.02310.58
4.4.80.0130.00710.58
4.4.70.0030.03710.58
4.4.60.0030.03010.58
4.4.50.0100.03010.58
4.4.40.0000.05710.58
4.4.30.0030.01710.58
4.4.20.0000.02010.58
4.4.10.0000.02710.58
4.4.00.0030.05310.58
4.3.110.0000.03310.58
4.3.100.0000.03310.58
4.3.90.0030.01310.58
4.3.80.0030.03010.58
4.3.70.0000.02010.58
4.3.60.0030.02310.58
4.3.50.0000.02310.58
4.3.40.0100.02710.58
4.3.30.0000.03710.58
4.3.20.0030.03310.58
4.3.10.0000.03010.58
4.3.00.0030.02710.58

preferences:
62.51 ms | 400 KiB | 5 Q