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.0090.00618.27
8.3.60.0000.01416.88
8.3.50.0080.00721.98
8.3.40.0110.00418.88
8.3.30.0140.00719.04
8.3.20.0040.00420.16
8.3.10.0070.00023.48
8.3.00.0040.00420.86
8.2.180.0080.00818.41
8.2.170.0000.01522.96
8.2.160.0070.00720.43
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0030.01426.16
8.2.120.0060.00322.26
8.2.110.0030.00622.08
8.2.100.0080.00417.91
8.2.90.0050.00319.26
8.2.80.0000.00817.97
8.2.70.0090.00017.61
8.2.60.0040.00418.03
8.2.50.0060.00318.07
8.2.40.0000.00918.09
8.2.30.0050.00218.25
8.2.20.0000.00817.79
8.2.10.0050.00317.69
8.2.00.0000.00817.86
8.1.280.0110.01125.92
8.1.270.0040.00423.84
8.1.260.0070.00326.35
8.1.250.0040.00428.09
8.1.240.0000.00923.88
8.1.230.0070.00419.07
8.1.220.0030.00617.74
8.1.210.0030.00518.77
8.1.200.0070.00317.60
8.1.190.0080.00017.64
8.1.180.0000.00818.10
8.1.170.0000.01118.83
8.1.160.0040.00421.98
8.1.150.0040.00418.69
8.1.140.0080.00017.38
8.1.130.0040.00417.88
8.1.120.0040.00417.38
8.1.110.0080.00017.54
8.1.100.0070.00017.54
8.1.90.0040.00417.43
8.1.80.0000.00917.48
8.1.70.0040.00417.46
8.1.60.0000.00817.69
8.1.50.0040.00417.63
8.1.40.0000.00817.57
8.1.30.0080.00017.62
8.1.20.0040.00417.72
8.1.10.0040.00417.55
8.1.00.0060.00617.48
8.0.300.0040.00418.77
8.0.290.0040.00417.30
8.0.280.0040.00418.41
8.0.270.0030.00517.32
8.0.260.0030.00316.87
8.0.250.0000.00716.95
8.0.240.0000.00816.91
8.0.230.0030.00516.94
8.0.220.0030.00316.86
8.0.210.0030.00316.98
8.0.200.0040.00416.98
8.0.190.0050.00217.02
8.0.180.0060.00316.90
8.0.170.0080.00017.02
8.0.160.0070.00016.89
8.0.150.0040.00416.87
8.0.140.0070.00016.90
8.0.130.0030.00313.40
8.0.120.0000.00816.85
8.0.110.0040.00416.93
8.0.100.0070.00016.95
8.0.90.0040.00416.83
8.0.80.0080.00716.86
8.0.70.0040.00416.85
8.0.60.0060.00316.90
8.0.50.0040.00416.79
8.0.30.0130.00817.23
8.0.20.0110.00817.40
8.0.10.0070.00016.98
8.0.00.0080.01016.83
7.4.330.0000.00615.02
7.4.320.0040.00416.61
7.4.300.0060.00016.66
7.4.290.0000.00716.68
7.4.280.0050.00216.66
7.4.270.0070.00016.74
7.4.260.0070.00016.61
7.4.250.0000.00716.49
7.4.240.0010.00616.46
7.4.230.0040.00416.78
7.4.220.0040.01116.65
7.4.210.0090.00816.52
7.4.200.0000.00716.63
7.4.190.0070.00016.74
7.4.160.0130.00316.70
7.4.150.0110.00817.40
7.4.140.0110.01017.86
7.4.130.0030.01316.47
7.4.120.0110.00816.48
7.4.110.0090.00916.57
7.4.100.0080.01116.53
7.4.90.0090.00616.42
7.4.80.0120.00619.39
7.4.70.0120.00316.35
7.4.60.0070.01116.36
7.4.50.0000.00816.54
7.4.40.0030.01222.77
7.4.30.0080.01516.76
7.4.00.0000.01314.79
7.3.330.0050.00013.38
7.3.320.0000.00513.37
7.3.310.0030.00316.43
7.3.300.0030.00316.47
7.3.290.0070.01416.44
7.3.280.0070.00816.45
7.3.270.0120.00417.40
7.3.260.0030.01416.46
7.3.250.0120.00716.58
7.3.240.0100.01316.46
7.3.230.0100.00716.62
7.3.210.0090.00916.40
7.3.200.0090.00919.39
7.3.190.0160.00616.40
7.3.180.0070.01016.32
7.3.170.0060.01216.68
7.3.160.0060.01016.38
7.3.120.0120.00314.63
7.3.10.0090.00516.54
7.3.00.0080.00516.42
7.2.330.0030.01316.57
7.2.320.0130.00316.64
7.2.310.0140.00816.46
7.2.300.0030.01416.84
7.2.290.0230.00016.47
7.2.130.0050.00716.82
7.2.120.0070.00816.33
7.2.110.0040.00816.78
7.2.100.0080.00716.87
7.2.90.0090.00716.70
7.2.80.0070.01017.04
7.2.70.0100.00716.74
7.2.60.0030.01216.64
7.2.50.0100.00516.69
7.2.40.0060.00816.73
7.2.30.0110.00316.84
7.2.20.0030.01016.70
7.2.10.0130.00416.70
7.2.00.0080.00816.79
7.1.250.0040.00915.53
7.1.240.0040.00415.96
7.1.230.0120.00915.84
7.1.220.0040.01115.51
7.1.210.0030.01415.87
7.1.200.0130.01015.68
7.1.190.0040.01115.78
7.1.180.0000.01615.74
7.1.170.0070.00715.76
7.1.160.0070.00715.47
7.1.150.0060.00615.45
7.1.140.0060.00915.77
7.1.130.0070.01015.77
7.1.120.0090.00615.50
7.1.110.0100.00315.91
7.1.100.0060.00616.98
7.1.90.0030.01415.61
7.1.80.0120.00315.77
7.1.70.0110.00516.36
7.1.60.0120.00917.51
7.1.50.0060.00716.33
7.1.40.0040.01115.78
7.1.30.0000.01315.80
7.1.20.0040.01115.53
7.1.10.0130.00315.79
7.1.00.0030.04419.09
7.0.330.0000.01115.21
7.0.320.0030.00615.30
7.0.310.0000.00915.36
7.0.300.0080.00815.30
7.0.290.0040.00715.33
7.0.280.0030.00915.20
7.0.270.0000.01215.22
7.0.260.0030.01115.20
7.0.250.0090.00315.08
7.0.240.0040.00415.43
7.0.230.0040.01115.44
7.0.220.0140.00415.28
7.0.210.0090.00615.24
7.0.200.0020.00616.13
7.0.190.0000.00915.56
7.0.180.0030.01315.05
7.0.170.0070.00715.54
7.0.160.0000.00915.36
7.0.150.0100.00315.29
7.0.140.0090.03618.69
7.0.130.0030.01315.09
7.0.120.0100.00315.49
7.0.110.0110.00315.25
7.0.100.0030.01015.43
7.0.90.0310.04417.59
7.0.80.0270.02817.58
7.0.70.0190.02917.64
7.0.60.0250.02317.76
7.0.50.0250.02217.93
7.0.40.0020.02516.85
7.0.30.0070.02716.79
7.0.20.0070.02216.76
7.0.10.0050.02116.55
7.0.00.0030.02816.76
5.6.380.0120.00613.96
5.6.370.0150.01014.38
5.6.360.0090.01114.31
5.6.350.0060.00614.24
5.6.340.0070.01014.48
5.6.330.0110.00714.13
5.6.320.0070.00314.25
5.6.310.0140.00714.54
5.6.300.0170.00614.00
5.6.290.0100.00314.34
5.6.280.0080.04817.47
5.6.270.0060.01014.39
5.6.260.0060.00614.14
5.6.250.0030.01414.02
5.6.240.0070.02217.55
5.6.230.0000.02917.56
5.6.220.0030.02517.43
5.6.210.0030.02717.43
5.6.200.0020.02917.50
5.6.190.0090.02217.54
5.6.180.0080.02417.63
5.6.170.0030.02517.65
5.6.160.0070.02217.68
5.6.150.0020.02417.57
5.6.140.0030.02317.57
5.6.130.0060.02317.59
5.6.120.0070.02317.45
5.6.110.0080.02217.65
5.6.100.0040.02417.68
5.6.90.0090.02217.54
5.6.80.0070.02617.40
5.6.70.0110.01717.21
5.6.60.0060.03817.30
5.6.50.0030.04217.34
5.6.40.0070.02517.26
5.6.30.0050.04417.27
5.6.20.0070.04317.39
5.6.10.0050.04317.18
5.6.00.0080.04217.21
5.5.380.0030.03515.77
5.5.370.0030.02615.93
5.5.360.0020.02615.89
5.5.350.0060.02315.94
5.5.340.0020.02516.03
5.5.330.0010.02615.99
5.5.320.0020.02415.80
5.5.310.0090.01816.00
5.5.300.0030.03016.11
5.5.290.0030.03116.07
5.5.280.0030.02715.93
5.5.270.0070.02115.84
5.5.260.0070.02315.91
5.5.250.0030.02015.89
5.5.240.0020.02415.45
5.5.230.0070.01815.65
5.5.220.0050.04215.74
5.5.210.0120.03315.54
5.5.200.0070.03715.46
5.5.190.0100.03015.50
5.5.180.0110.03615.51
5.5.170.0040.00811.24
5.5.160.0070.02715.71
5.5.150.0100.03715.43
5.5.140.0070.03315.58
5.5.130.0080.03815.64
5.5.120.0060.04115.52
5.5.110.0020.04415.59
5.5.100.0070.02715.60
5.5.90.0080.03515.53
5.5.80.0020.04515.37
5.5.70.0070.03315.67
5.5.60.0070.04215.31
5.5.50.0070.03815.65
5.5.40.0100.03615.53
5.5.30.0070.03515.62
5.5.20.0050.03015.62
5.5.10.0020.02715.62
5.5.00.0050.03715.48
5.4.450.0030.02815.10
5.4.440.0070.02215.23
5.4.430.0070.01715.22
5.4.420.0050.02715.11
5.4.410.0040.02214.98
5.4.400.0070.02015.13
5.4.390.0040.02114.86
5.4.380.0070.04215.11
5.4.370.0070.03414.98
5.4.360.0080.02614.93
5.4.350.0120.03415.05
5.4.340.0040.04414.94
5.4.330.0030.00310.90
5.4.320.0070.04215.08
5.4.310.0090.03515.16
5.4.300.0020.02415.00
5.4.290.0030.02014.86
5.4.280.0030.03915.08
5.4.270.0050.03514.91
5.4.260.0070.02515.02
5.4.250.0080.04015.13
5.4.240.0080.03815.12
5.4.230.0050.04114.97
5.4.220.0070.03215.09
5.4.210.0030.04714.97
5.4.200.0030.03915.07
5.4.190.0080.02514.96
5.4.180.0100.03315.11
5.4.170.0060.02815.04
5.4.160.0100.03615.06
5.4.150.0060.02515.07
5.4.140.0020.02813.65
5.4.130.0050.04113.74
5.4.120.0070.03913.58
5.4.110.0090.03913.64
5.4.100.0030.02813.77
5.4.90.0020.02513.81
5.4.80.0110.03213.68
5.4.70.0050.04013.78
5.4.60.0050.04013.70
5.4.50.0100.02713.71
5.4.40.0070.02313.80
5.4.30.0050.04013.57
5.4.20.0060.02613.59
5.4.10.0100.02013.57
5.4.00.0050.02413.43
5.3.290.0070.03212.77
5.3.280.0080.03612.60
5.3.270.0090.02812.73
5.3.260.0020.02912.61
5.3.250.0050.02512.75
5.3.240.0020.02612.69
5.3.230.0080.03212.63
5.3.220.0020.03012.60
5.3.210.0050.04312.64
5.3.200.0030.04112.59
5.3.190.0060.04212.60
5.3.180.0010.04412.61
5.3.170.0060.04012.66
5.3.160.0060.02812.58
5.3.150.0040.03912.71
5.3.140.0020.02712.63
5.3.130.0000.04612.68
5.3.120.0100.02212.53
5.3.110.0070.03912.44
5.3.100.0090.04112.24
5.3.90.0090.03112.30
5.3.80.0070.03912.32
5.3.70.0090.02312.29
5.3.60.0050.04112.28
5.3.50.0050.03812.36
5.3.40.0030.03012.05
5.3.30.0080.03312.25
5.3.20.0050.02712.17
5.3.10.0100.02712.09
5.3.00.0060.03311.93
5.2.170.0070.03610.35
5.2.160.0030.03810.52
5.2.150.0080.03410.35
5.2.140.0040.03310.35
5.2.130.0030.03310.37
5.2.120.0080.02110.43
5.2.110.0000.03710.41
5.2.100.0030.02510.32
5.2.90.0020.02710.21
5.2.80.0050.01810.12
5.2.70.0060.03210.23
5.2.60.0050.02310.32
5.2.50.0060.02110.33
5.2.40.0020.02910.31
5.2.30.0090.03010.23
5.2.20.0050.02810.06
5.2.10.0020.0299.94
5.2.00.0070.0279.97
5.1.60.0050.0289.29
5.1.50.0060.0139.28
5.1.40.0020.0289.20
5.1.30.0110.0179.67
5.1.20.0070.0309.66
5.1.10.0040.0309.50
5.1.00.0070.0209.44
5.0.50.0010.0208.56
5.0.40.0020.0198.49
5.0.30.0050.0308.38
5.0.20.0060.0138.40
5.0.10.0040.0208.39
5.0.00.0030.0318.33
4.4.90.0020.0167.96
4.4.80.0010.0207.96
4.4.70.0030.0137.96
4.4.60.0030.0187.96
4.4.50.0020.0177.96
4.4.40.0050.0177.96
4.4.30.0080.0137.96
4.4.20.0000.0227.96
4.4.10.0030.0177.96
4.4.00.0020.0277.96
4.3.110.0020.0177.96
4.3.100.0000.0217.96
4.3.90.0050.0177.96
4.3.80.0000.0227.96
4.3.70.0030.0157.96
4.3.60.0040.0187.96
4.3.50.0020.0167.96
4.3.40.0000.0297.96
4.3.30.0000.0177.96
4.3.20.0020.0217.96
4.3.10.0020.0157.96
4.3.00.0020.0137.96

preferences:
51.81 ms | 401 KiB | 5 Q