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) { if (!mb_check_encoding($value, 'UTF-8')) { return 'null'; } $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\\\"/"); } } } $str = ''; for ($i=0;$i<=300;$i++) { $str .= chr($i); } $str .= chr(127); var_dump(json_encode(array("test" => $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.0140.00716.88
8.3.50.0110.00716.45
8.3.40.0060.00918.92
8.3.30.0110.00418.80
8.3.20.0080.00018.91
8.3.10.0000.00820.58
8.3.00.0030.00619.16
8.2.180.0110.00816.75
8.2.170.0070.01122.96
8.2.160.0100.00321.01
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0050.00320.93
8.2.110.0070.00320.39
8.2.100.0090.00317.77
8.2.90.0060.00319.40
8.2.80.0000.00817.97
8.2.70.0030.00617.62
8.2.60.0060.00317.93
8.2.50.0040.00418.07
8.2.40.0080.00318.26
8.2.30.0030.00818.12
8.2.20.0040.00417.70
8.2.10.0000.00717.75
8.2.00.0000.00817.81
8.1.280.0040.01225.92
8.1.270.0040.00424.66
8.1.260.0120.00426.35
8.1.250.0000.00828.09
8.1.240.0060.00322.25
8.1.230.0040.00817.64
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0000.00917.35
8.1.190.0040.00417.66
8.1.180.0030.00518.10
8.1.170.0030.00619.09
8.1.160.0030.00519.00
8.1.150.0030.00518.70
8.1.140.0050.00317.51
8.1.130.0020.00517.95
8.1.120.0030.00317.51
8.1.110.0000.00717.54
8.1.100.0040.00417.57
8.1.90.0040.00417.50
8.1.80.0030.00317.43
8.1.70.0030.00317.51
8.1.60.0080.00017.53
8.1.50.0030.00617.43
8.1.40.0040.00517.46
8.1.30.0000.00817.54
8.1.20.0030.00617.65
8.1.10.0000.00817.58
8.1.00.0000.00817.42
8.0.300.0000.00818.77
8.0.290.0040.00416.75
8.0.280.0000.00718.44
8.0.270.0000.00717.33
8.0.260.0060.00316.88
8.0.250.0000.00717.06
8.0.240.0000.00917.05
8.0.230.0000.00716.89
8.0.220.0040.00416.86
8.0.210.0040.00416.86
8.0.200.0070.00017.00
8.0.190.0040.00416.90
8.0.180.0040.00417.01
8.0.170.0000.00916.96
8.0.160.0030.00516.93
8.0.150.0080.00016.86
8.0.140.0060.00316.92
8.0.130.0030.00313.42
8.0.120.0030.00516.80
8.0.110.0040.00416.93
8.0.100.0040.00416.98
8.0.90.0040.00416.78
8.0.80.0090.00616.95
8.0.70.0040.00416.84
8.0.60.0000.00816.93
8.0.50.0000.00716.94
8.0.30.0070.01717.10
8.0.20.0100.01017.35
8.0.10.0040.00416.90
8.0.00.0100.00916.77
7.4.330.0000.00513.02
7.4.320.0070.00016.66
7.4.300.0060.00016.59
7.4.290.0070.00016.50
7.4.280.0060.00316.51
7.4.270.0000.00816.61
7.4.260.0030.00313.36
7.4.250.0060.00316.52
7.4.240.0020.00516.59
7.4.230.0030.00316.56
7.4.220.0060.00916.53
7.4.210.0060.00816.56
7.4.200.0040.00416.63
7.4.190.0000.00716.68
7.4.160.0050.01416.70
7.4.150.0260.01416.54
7.4.140.0040.01416.64
7.4.130.0110.01016.56
7.4.120.0100.00816.53
7.4.110.0070.01116.64
7.4.100.0140.00316.50
7.4.90.0080.01116.57
7.4.80.0070.01119.39
7.4.70.0100.00716.41
7.4.60.0130.00316.49
7.4.50.0040.00816.72
7.4.40.0060.00616.66
7.4.30.0030.01316.49
7.4.10.0040.01515.14
7.4.00.0050.00914.97
7.3.330.0030.00313.45
7.3.320.0030.00313.30
7.3.310.0000.00716.25
7.3.300.0000.00716.30
7.3.290.0040.01116.43
7.3.280.0070.00916.43
7.3.270.0140.00516.70
7.3.260.0070.01016.49
7.3.250.0170.00316.48
7.3.240.0120.00616.50
7.3.230.0110.00516.64
7.3.210.0090.00916.70
7.3.200.0100.00616.48
7.3.190.0190.00016.55
7.3.180.0040.01216.74
7.3.170.0160.00016.73
7.3.160.0090.00616.53
7.3.130.0100.00714.84
7.3.120.0100.00714.78
7.3.110.0070.00715.19
7.3.100.0030.01014.87
7.3.90.0030.01014.70
7.3.80.0070.00714.59
7.3.70.0040.01214.60
7.3.60.0120.00314.87
7.3.50.0000.01214.96
7.3.40.0070.00714.95
7.3.30.0060.00614.91
7.3.20.0090.00416.51
7.3.10.0030.00916.75
7.3.00.0000.01116.77
7.2.330.0110.00716.68
7.2.320.0120.00616.76
7.2.310.0090.01216.62
7.2.300.0100.01316.75
7.2.290.0030.01416.53
7.2.260.0030.01314.84
7.2.250.0040.01115.16
7.2.240.0000.01615.01
7.2.230.0090.00914.97
7.2.220.0000.01115.01
7.2.210.0070.00714.98
7.2.200.0060.00915.18
7.2.190.0060.00915.27
7.2.180.0030.00714.79
7.2.170.0070.01015.15
7.2.160.0070.01115.08
7.2.150.0060.00616.85
7.2.140.0080.00817.01
7.2.130.0000.00917.04
7.2.120.0040.00716.61
7.2.110.0070.00717.06
7.2.100.0070.00716.99
7.2.90.0060.00916.82
7.2.80.0070.00316.95
7.2.70.0030.00717.02
7.2.60.0070.01016.57
7.2.50.0040.00716.94
7.2.40.0040.01116.95
7.2.30.0120.00616.96
7.2.20.0030.01516.88
7.2.10.0030.00716.84
7.2.00.0070.00716.97
7.1.330.0070.00715.79
7.1.320.0050.00515.95
7.1.310.0030.01416.15
7.1.300.0070.00715.92
7.1.290.0080.00515.64
7.1.280.0060.00915.83
7.1.270.0040.00815.76
7.1.260.0060.00915.71
7.1.250.0000.01215.77
7.1.240.0040.01115.93
7.1.230.0060.00615.75
7.1.220.0000.01115.71
7.1.210.0040.00715.89
7.1.200.0090.00415.98
7.1.190.0070.00315.92
7.1.180.0080.00415.94
7.1.170.0040.00815.85
7.1.160.0030.01015.79
7.1.150.0000.01215.70
7.1.140.0070.00715.95
7.1.130.0040.00715.61
7.1.120.0030.01216.06
7.1.110.0000.00915.98
7.1.100.0020.00817.13
7.1.90.0030.01015.56
7.1.80.0090.00615.98
7.1.70.0020.01016.39
7.1.60.0060.01417.44
7.1.50.0080.01016.23
7.1.40.0090.00315.81
7.1.30.0080.00415.82
7.1.20.0060.00915.57
7.1.10.0070.00715.84
7.1.00.0050.04119.09
7.0.330.0030.00915.23
7.0.320.0040.00415.55
7.0.310.0000.00915.41
7.0.300.0060.00615.36
7.0.290.0030.00615.27
7.0.280.0030.01015.55
7.0.270.0030.00715.57
7.0.260.0040.00415.34
7.0.250.0070.00715.54
7.0.240.0070.00715.55
7.0.230.0090.00615.55
7.0.220.0030.00615.43
7.0.210.0030.01315.49
7.0.200.0050.00616.12
7.0.190.0030.01015.24
7.0.180.0040.00815.59
7.0.170.0030.01015.57
7.0.160.0090.00615.35
7.0.150.0070.00715.24
7.0.140.0050.03918.54
7.0.130.0060.01015.53
7.0.120.0050.03818.74
7.0.110.0040.00815.60
7.0.100.0000.01315.54
7.0.90.0080.04317.72
7.0.80.0100.03817.58
7.0.70.0060.04617.74
7.0.60.0060.02617.67
7.0.50.0080.03818.01
7.0.40.0100.02216.96
7.0.30.0060.03016.63
7.0.20.0090.03616.65
7.0.10.0100.04316.85
7.0.00.0070.03716.85
5.6.400.0090.00614.69
5.6.390.0030.00814.16
5.6.380.0070.00714.68
5.6.370.0080.00514.46
5.6.360.0070.00314.32
5.6.350.0060.00614.29
5.6.340.0070.00714.42
5.6.330.0060.00614.57
5.6.320.0030.01014.54
5.6.310.0040.00414.62
5.6.300.0000.00914.43
5.6.290.0120.00614.34
5.6.280.0070.03917.79
5.6.270.0090.00314.36
5.6.260.0120.00014.26
5.6.250.0040.01114.37
5.6.240.0090.03817.43
5.6.230.0050.03417.47
5.6.220.0120.04017.44
5.6.210.0030.02717.54
5.6.200.0050.02817.72
5.6.190.0080.04017.66
5.6.180.0030.02917.68
5.6.170.0030.03017.53
5.6.160.0100.04617.65
5.6.150.0050.04917.76
5.6.140.0070.02617.76
5.6.130.0030.03017.74
5.6.120.0090.02917.77
5.6.110.0100.05017.80
5.6.100.0080.03817.54
5.6.90.0080.02717.62
5.6.80.0030.03317.43
5.6.70.0080.02717.45
5.6.60.0050.02817.40
5.6.50.0050.03417.55
5.6.40.0050.04517.23
5.6.30.0070.03817.27
5.6.20.0100.03717.27
5.6.10.0070.04017.45
5.6.00.0070.04517.19
5.5.380.0050.02517.27
5.5.370.0070.04717.30
5.5.360.0070.03417.50
5.5.350.0080.02417.27
5.5.340.0060.03617.43
5.5.330.0050.03117.59
5.5.320.0080.04217.43
5.5.310.0030.04317.54
5.5.300.0080.03717.70
5.5.290.0070.04617.67
5.5.280.0050.03217.49
5.5.270.0070.02817.61
5.5.260.0030.04517.71
5.5.250.0050.04717.42
5.5.240.0030.04517.19
5.5.230.0150.03717.24
5.5.220.0020.03717.27
5.5.210.0170.01817.07
5.5.200.0070.02017.28
5.5.190.0090.04117.18
5.5.180.0090.03017.07
5.5.170.0080.00813.76
5.5.160.0100.04317.23
5.5.150.0110.02117.20
5.5.140.0040.02717.31
5.5.130.0130.03517.24
5.5.120.0050.03017.19
5.5.110.0030.04017.20
5.5.100.0060.04917.01
5.5.90.0090.03517.06
5.5.80.0030.03017.01
5.5.70.0090.03016.97
5.5.60.0060.04317.12
5.5.50.0030.03817.17
5.5.40.0070.02516.96
5.5.30.0060.02217.19
5.5.20.0030.04317.21
5.5.10.0020.04016.84
5.5.00.0190.01517.13
5.4.450.0070.03615.24
5.4.440.0030.04315.32
5.4.430.0020.04515.14
5.4.420.0030.04015.38
5.4.410.0040.02615.34
5.4.400.0120.03014.99
5.4.390.0020.03115.11
5.4.380.0060.03915.09
5.4.370.0080.04014.91
5.4.360.0070.04015.07
5.4.350.0050.02715.14
5.4.340.0060.02114.93
5.4.330.0040.00410.93
5.4.320.0120.01815.09
5.4.310.0040.02615.03
5.4.300.0050.04215.05
5.4.290.0030.02315.09
5.4.280.0070.03514.89
5.4.270.0050.03814.91
5.4.260.0060.04114.86
5.4.250.0050.03014.97
5.4.240.0080.02214.86
5.4.230.0080.03515.05
5.4.220.0030.02914.86
5.4.210.0060.02214.99
5.4.200.0090.03714.77
5.4.190.0070.03715.07
5.4.180.0070.03715.03
5.4.170.0030.02514.95
5.4.160.0070.02314.95
5.4.150.0040.04215.05
5.4.140.0150.01513.63
5.4.130.0070.01713.52
5.4.120.0090.02513.59
5.4.110.0050.02313.71
5.4.100.0050.02513.53
5.4.90.0050.03713.83
5.4.80.0030.02813.68
5.4.70.0020.02313.65
5.4.60.0100.03013.61
5.4.50.0050.04013.72
5.4.40.0070.02813.57
5.4.30.0080.03613.76
5.4.20.0060.03213.77
5.4.10.0050.02213.66
5.4.00.0030.04313.40
5.3.290.0050.03812.67
5.3.280.0060.03812.70
5.3.270.0050.03812.65
5.3.260.0020.03212.71
5.3.250.0020.03312.61
5.3.240.0050.03812.55
5.3.230.0050.03612.63
5.3.220.0020.04012.46
5.3.210.0080.02012.47
5.3.200.0030.04412.52
5.3.190.0030.02612.55
5.3.180.0030.02212.72
5.3.170.0090.03812.66
5.3.160.0060.02012.68
5.3.150.0050.04012.61
5.3.140.0090.03412.70
5.3.130.0090.02412.62
5.3.120.0070.02312.60
5.3.110.0050.03812.60
5.3.100.0070.02412.29
5.3.90.0030.02312.42
5.3.80.0130.03312.43
5.3.70.0070.02012.43
5.3.60.0100.02012.33
5.3.50.0040.04312.15
5.3.40.0020.03112.30
5.3.30.0100.03312.30
5.3.20.0080.02812.14
5.3.10.0060.03312.01
5.3.00.0030.04611.97
5.2.170.0000.04311.29
5.2.160.0130.04311.08
5.2.150.0030.06011.08
5.2.140.0070.06011.04
5.2.130.0030.03311.05
5.2.120.0000.06011.03
5.2.110.0100.04711.20
5.2.100.0030.04011.14
5.2.90.0070.05011.19
5.2.80.0070.03311.05
5.2.70.0070.03311.21
5.2.60.0070.02711.11
5.2.50.0100.06011.05
5.2.40.0030.04311.09
5.2.30.0030.03711.01
5.2.20.0100.05711.05
5.2.10.0030.04710.84
5.2.00.0070.06010.78
5.1.60.0030.03010.23
5.1.50.0000.03310.21
5.1.40.0030.03010.13
5.1.30.0100.04010.54
5.1.20.0070.02710.40
5.1.10.0100.05010.10
5.1.00.0030.02710.18
5.0.50.0000.0238.71
5.0.40.0030.0278.53
5.0.30.0030.0538.36
5.0.20.0070.0378.30
5.0.10.0030.0438.34
5.0.00.0100.0378.33
4.4.90.0000.0177.35
4.4.80.0000.0377.35
4.4.70.0000.0277.35
4.4.60.0030.0207.35
4.4.50.0030.0377.35
4.4.40.0000.0337.35
4.4.30.0000.0337.35
4.4.20.0030.0307.35
4.4.10.0000.0377.35
4.4.00.0030.0437.35
4.3.110.0070.0307.35
4.3.100.0030.0237.35
4.3.90.0030.0207.35
4.3.80.0070.0277.35
4.3.70.0030.0177.35
4.3.60.0030.0277.35
4.3.50.0030.0307.35
4.3.40.0070.0437.35
4.3.30.0000.0307.35
4.3.20.0000.0237.35
4.3.10.0000.0237.35
4.3.00.0000.0337.35

preferences:
43.89 ms | 401 KiB | 5 Q