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 ($value !== mb_convert_encoding("UTF-8", "UTF-8", $value)) { return 'null'; } $pattern = "@[\x08-x010\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.70.0070.01016.75
8.3.60.0110.01118.55
8.3.50.0120.00722.00
8.3.40.0060.00918.70
8.3.30.0090.00619.22
8.3.20.0080.00020.20
8.3.10.0040.00421.97
8.3.00.0080.00022.34
8.2.180.0110.00718.29
8.2.170.0150.00022.96
8.2.160.0110.00420.84
8.2.150.0000.00824.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0060.00319.72
8.2.110.0100.00022.04
8.2.100.0080.00317.72
8.2.90.0040.00419.19
8.2.80.0000.00817.97
8.2.70.0000.00817.50
8.2.60.0080.00018.05
8.2.50.0040.00418.07
8.2.40.0080.00018.14
8.2.30.0040.00418.25
8.2.20.0000.00717.88
8.2.10.0050.00217.76
8.2.00.0000.00817.63
8.1.280.0070.00725.92
8.1.270.0000.00823.71
8.1.260.0000.00826.35
8.1.250.0090.00028.09
8.1.240.0040.00423.83
8.1.230.0090.00319.29
8.1.220.0000.00817.91
8.1.210.0060.00318.77
8.1.200.0030.00617.48
8.1.190.0000.00817.64
8.1.180.0030.00618.10
8.1.170.0090.00318.84
8.1.160.0040.00422.11
8.1.150.0040.00418.70
8.1.140.0050.00317.45
8.1.130.0030.00317.89
8.1.120.0040.00417.52
8.1.110.0070.00017.57
8.1.100.0070.00017.46
8.1.90.0080.00017.53
8.1.80.0040.00417.57
8.1.70.0000.00717.48
8.1.60.0030.00617.68
8.1.50.0000.00717.47
8.1.40.0020.00517.58
8.1.30.0000.00817.68
8.1.20.0030.00517.76
8.1.10.0040.00417.47
8.1.00.0000.00817.48
8.0.300.0070.00018.77
8.0.290.0040.00417.28
8.0.280.0000.00818.51
8.0.270.0040.00417.32
8.0.260.0070.00016.87
8.0.250.0040.00417.03
8.0.240.0000.00716.92
8.0.230.0000.00716.97
8.0.220.0040.00416.94
8.0.210.0000.00816.96
8.0.200.0000.00617.03
8.0.190.0040.00416.89
8.0.180.0000.00916.86
8.0.170.0050.00316.99
8.0.160.0030.00616.96
8.0.150.0000.00716.87
8.0.140.0070.00016.78
8.0.130.0000.00613.40
8.0.120.0080.00016.81
8.0.110.0040.00416.80
8.0.100.0050.00316.82
8.0.90.0000.00716.97
8.0.80.0030.01316.97
8.0.70.0030.00516.87
8.0.60.0000.00716.77
8.0.50.0080.00016.91
8.0.30.0150.00717.15
8.0.20.0080.01217.40
8.0.10.0050.00216.91
8.0.00.0140.00516.80
7.4.330.0050.00015.07
7.4.320.0030.00316.49
7.4.300.0000.00716.68
7.4.290.0070.00016.65
7.4.280.0030.00316.65
7.4.270.0000.00916.67
7.4.260.0060.00316.67
7.4.250.0040.00416.58
7.4.240.0040.00416.64
7.4.230.0030.00416.65
7.4.220.0060.01016.57
7.4.210.0090.00816.59
7.4.200.0050.00216.68
7.4.190.0030.00316.68
7.4.160.0120.00416.56
7.4.150.0110.00917.40
7.4.140.0090.01117.86
7.4.130.0020.01616.42
7.4.120.0140.00316.66
7.4.110.0150.00316.58
7.4.100.0140.01016.50
7.4.90.0070.01016.60
7.4.80.0090.00919.39
7.4.70.0070.01016.38
7.4.60.0030.01416.57
7.4.50.0030.00316.29
7.4.40.0090.00322.77
7.4.30.0100.00716.71
7.4.00.0050.01014.99
7.3.330.0020.00213.16
7.3.320.0020.00213.43
7.3.310.0040.00416.32
7.3.300.0040.00416.30
7.3.290.0070.00716.42
7.3.280.0120.00816.40
7.3.270.0100.01117.40
7.3.260.0140.01116.70
7.3.250.0050.01316.55
7.3.240.0130.00316.73
7.3.230.0100.00716.48
7.3.210.0150.00316.50
7.3.200.0060.01519.39
7.3.190.0120.00916.44
7.3.180.0120.00316.55
7.3.170.0110.01116.36
7.3.160.0140.00316.70
7.3.120.0100.00814.89
7.3.110.0090.00914.88
7.3.100.0040.01114.78
7.3.90.0070.00415.05
7.3.80.0030.01014.86
7.3.70.0000.01414.65
7.3.60.0100.00314.77
7.3.50.0100.00714.88
7.3.40.0090.00914.80
7.3.30.0080.00414.68
7.3.20.0030.01616.66
7.3.10.0060.00916.79
7.3.00.0030.01516.77
7.2.330.0070.01016.77
7.2.320.0140.00416.83
7.2.310.0120.00616.84
7.2.300.0140.00716.73
7.2.290.0100.00716.49
7.2.250.0100.01015.00
7.2.240.0000.01815.25
7.2.230.0040.01115.16
7.2.220.0070.01014.89
7.2.210.0030.01015.29
7.2.200.0000.01414.95
7.2.190.0030.00615.04
7.2.180.0160.00015.02
7.2.170.0070.01115.07
7.2.160.0030.01015.00
7.2.150.0100.00616.88
7.2.140.0030.01416.91
7.2.130.0070.01016.75
7.2.120.0130.01016.92
7.2.110.0110.00716.89
7.2.100.0100.00916.86
7.2.90.0000.01216.98
7.2.80.0000.01117.05
7.2.70.0040.01416.62
7.2.60.0060.00316.99
7.2.50.0100.00316.86
7.2.40.0000.01516.85
7.2.30.0030.00617.09
7.2.20.0060.00916.99
7.2.10.0060.00616.86
7.2.00.0080.00318.06
7.1.330.0070.01015.84
7.1.320.0080.00815.85
7.1.310.0000.00815.52
7.1.300.0080.00816.00
7.1.290.0070.00315.72
7.1.280.0100.00715.91
7.1.270.0030.01015.67
7.1.260.0030.01315.82
7.1.250.0030.01015.65
7.1.240.0040.01115.71
7.1.230.0100.00715.45
7.1.220.0070.00715.81
7.1.210.0040.00815.75
7.1.200.0040.01115.77
7.1.190.0030.00915.63
7.1.180.0040.01115.71
7.1.170.0080.00415.71
7.1.160.0100.00315.86
7.1.150.0000.01215.80
7.1.140.0030.00615.79
7.1.130.0100.00315.88
7.1.120.0000.00815.66
7.1.110.0030.01015.85
7.1.100.0060.00816.79
7.1.90.0060.00915.90
7.1.80.0100.00415.82
7.1.70.0020.01116.33
7.1.60.0090.00817.86
7.1.50.0070.01216.37
7.1.40.0030.01315.93
7.1.30.0000.01315.77
7.1.20.0040.00715.87
7.1.10.0090.00315.85
7.1.00.0070.04019.08
7.0.330.0070.00715.38
7.0.320.0060.00915.18
7.0.310.0070.00715.47
7.0.300.0060.00615.38
7.0.290.0090.00315.53
7.0.280.0100.00315.49
7.0.270.0060.00915.44
7.0.260.0040.01115.36
7.0.250.0090.00315.52
7.0.240.0030.00915.29
7.0.230.0030.01015.39
7.0.220.0090.00615.15
7.0.210.0060.00615.18
7.0.200.0050.01016.22
7.0.190.0040.01115.42
7.0.180.0040.01115.48
7.0.170.0030.01215.48
7.0.160.0040.01115.45
7.0.150.0110.00415.57
7.0.140.0070.04018.73
7.0.130.0000.01415.45
7.0.120.0030.00515.57
7.0.110.0030.01015.59
7.0.100.0070.01015.30
7.0.90.0410.03317.63
7.0.80.0310.03717.67
7.0.70.0350.02217.75
7.0.60.0250.02717.82
7.0.50.0070.04517.93
7.0.40.0020.04716.88
7.0.30.0070.03216.78
7.0.20.0050.04416.82
7.0.10.0030.03816.68
7.0.00.0070.04516.76
5.6.400.0110.00414.45
5.6.390.0060.01314.37
5.6.380.0040.01114.54
5.6.370.0100.00714.04
5.6.360.0000.00914.16
5.6.350.0030.01014.11
5.6.340.0000.00914.57
5.6.330.0000.01714.75
5.6.320.0070.00714.29
5.6.310.0070.01014.60
5.6.300.0000.01214.54
5.6.290.0060.00914.48
5.6.280.0050.04017.63
5.6.270.0060.00914.13
5.6.260.0110.00714.27
5.6.250.0070.01014.57
5.6.240.0080.03317.41
5.6.230.0130.04017.51
5.6.220.0080.02717.48
5.6.210.0050.03317.45
5.6.200.0030.04517.63
5.6.190.0140.02717.70
5.6.180.0050.04817.82
5.6.170.0070.04517.68
5.6.160.0070.04517.76
5.6.150.0120.03717.55
5.6.140.0090.02217.69
5.6.130.0090.04117.77
5.6.120.0050.04717.72
5.6.110.0050.04617.57
5.6.100.0060.04517.57
5.6.90.0080.04017.57
5.6.80.0050.04617.32
5.6.70.0090.04117.43
5.6.60.0050.04317.35
5.6.50.0020.02617.48
5.6.40.0030.04217.46
5.6.30.0050.04417.44
5.6.20.0070.02417.30
5.6.10.0050.04317.29
5.6.00.0030.03217.38
5.5.380.0070.04717.55
5.5.370.0140.03917.47
5.5.360.0030.05017.39
5.5.350.0070.03317.45
5.5.340.0060.04617.39
5.5.330.0060.04117.70
5.5.320.0020.03517.67
5.5.310.0050.03717.69
5.5.300.0060.02317.67
5.5.290.0050.02517.67
5.5.280.0050.04617.69
5.5.270.0060.04817.51
5.5.260.0050.04317.60
5.5.250.0020.02917.34
5.5.240.0130.03117.30
5.5.230.0030.03217.05
5.5.220.0060.03017.26
5.5.210.0080.04117.16
5.5.200.0070.04417.18
5.5.190.0030.04317.14
5.5.180.0060.02917.17
5.5.170.0070.01014.27
5.5.160.0070.02817.15
5.5.150.0040.04017.11
5.5.140.0080.02817.24
5.5.130.0080.03017.00
5.5.120.0050.03117.30
5.5.110.0050.03417.25
5.5.100.0090.03917.24
5.5.90.0150.03217.17
5.5.80.0120.03716.99
5.5.70.0030.03117.12
5.5.60.0050.04217.01
5.5.50.0080.03817.19
5.5.40.0070.03717.16
5.5.30.0070.04317.23
5.5.20.0080.04117.25
5.5.10.0070.02717.00
5.5.00.0060.03116.95
5.4.450.0130.03816.02
5.4.440.0080.03415.91
5.4.430.0030.04615.95
5.4.420.0030.04815.95
5.4.410.0030.03015.83
5.4.400.0030.04215.80
5.4.390.0000.03415.74
5.4.380.0100.03815.78
5.4.370.0100.03115.65
5.4.360.0080.04015.79
5.4.350.0020.02915.73
5.4.340.0060.03015.78
5.4.330.0090.00312.45
5.4.320.0070.02815.75
5.4.310.0080.03315.74
5.4.300.0070.03515.74
5.4.290.0130.03315.74
5.4.280.0070.03815.82
5.4.270.0040.03015.80
5.4.260.0130.03515.76
5.4.250.0060.03815.66
5.4.240.0060.03815.80
5.4.230.0100.03815.74
5.4.220.0030.04215.84
5.4.210.0050.03515.74
5.4.200.0050.04215.69
5.4.190.0060.03115.76
5.4.180.0050.02515.79
5.4.170.0020.04415.66
5.4.160.0070.04115.82
5.4.150.0050.04415.74
5.4.140.0090.03814.35
5.4.130.0060.03814.47
5.4.120.0090.02914.39
5.4.110.0120.03314.42
5.4.100.0090.03614.45
5.4.90.0030.03014.51
5.4.80.0060.02214.50
5.4.70.0050.04414.49
5.4.60.0070.03814.37
5.4.50.0100.03814.43
5.4.40.0040.02214.47
5.4.30.0050.04114.39
5.4.20.0100.02714.39
5.4.10.0110.03314.37
5.4.00.0080.03814.13
5.3.290.0120.02213.56
5.3.280.0030.03813.52
5.3.270.0060.04013.53
5.3.260.0080.02313.52
5.3.250.0050.04113.54
5.3.240.0060.03813.51
5.3.230.0050.03813.56
5.3.220.0070.03513.49
5.3.210.0080.02813.55
5.3.200.0030.04013.55
5.3.190.0020.04513.57
5.3.180.0050.03713.57
5.3.170.0050.04213.51
5.3.160.0050.04013.54
5.3.150.0030.03013.53
5.3.140.0120.03213.58
5.3.130.0050.03613.51
5.3.120.0110.03513.47
5.3.110.0050.02413.49
5.3.100.0020.03213.29
5.3.90.0080.03513.27
5.3.80.0080.04013.19
5.3.70.0050.04013.25
5.3.60.0030.03313.27
5.3.50.0020.04413.18
5.3.40.0050.03613.26
5.3.30.0100.02013.24
5.3.20.0060.03813.15
5.3.10.0020.03613.13
5.3.00.0030.02813.01
5.2.170.0070.06311.24
5.2.160.0130.05711.09
5.2.150.0070.04011.21
5.2.140.0000.06011.23
5.2.130.0030.04011.06
5.2.120.0070.06011.00
5.2.110.0100.04011.27
5.2.100.0030.06711.05
5.2.90.0030.03311.06
5.2.80.0000.07311.23
5.2.70.0070.06311.18
5.2.60.0030.06311.11
5.2.50.0030.06710.92
5.2.40.0030.06010.95
5.2.30.0070.06011.05
5.2.20.0070.05310.84
5.2.10.0000.06311.00
5.2.00.0070.05710.78
5.1.60.0030.04710.14
5.1.50.0030.0539.91
5.1.40.0030.04010.06
5.1.30.0030.04010.29
5.1.20.0000.04310.45
5.1.10.0000.0639.99
5.1.00.0070.05710.10
5.0.50.0000.0438.71
5.0.40.0070.0208.31
5.0.30.0030.0678.38
5.0.20.0030.0438.28
5.0.10.0070.0178.27
5.0.00.0030.0638.29
4.4.90.0070.0308.21
4.4.80.0030.0338.21
4.4.70.0070.0238.21
4.4.60.0070.0308.21
4.4.50.0000.0278.21
4.4.40.0000.0378.21
4.4.30.0000.0338.21
4.4.20.0000.0408.21
4.4.10.0000.0278.21
4.4.00.0000.0608.21
4.3.110.0030.0378.21
4.3.100.0030.0338.21
4.3.90.0000.0308.21
4.3.80.0030.0508.21
4.3.70.0070.0178.21
4.3.60.0000.0338.21
4.3.50.0000.0378.21
4.3.40.0000.0578.21
4.3.30.0030.0338.21
4.3.20.0070.0308.21
4.3.10.0030.0308.21
4.3.00.0000.0378.21

preferences:
65.51 ms | 401 KiB | 5 Q