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); } if ($assoc) { $it = get_object_vars($it); } else { $assoc = $it === array_values($it); } $data = array(); foreach ($it as $k => $v) { $v = _js_enc_value($v); if ($assoc) { $k = (string)$k; if (preg_match('//u', $k)) { $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 $value === null: case is_resource($value): return 'null'; case is_bool($value): return $value ? 'true' : 'false'; case is_string($value) && preg_match('//u', $value): return '"' . _js_uc_esc($value) . '"'; default: return $value; } } function _js_uc_esc($value) { $pattern = "@[\x08-\x0a\x0c\x0d\\\\\"/]|([^\x08-\x0a\x0c\x0d\x20-\x7f\\\\\"/])++@u"; 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\x0a\x0c\x0d\\\"/"); } } } $var = array( array( 'text', 1, 1.1, true, false, null, array(), new stdClass, ), array( '&\'/"' => "\r\n\t", '' => '', ), array( '0' => 'hoge', '1' => 'foo', ), (object)array( '0' => 'hoge', '1' => 'foo', ), array( '0' => 'hoge', '2' => 'foo', ), (object)array( '0' => 'hoge', '2' => 'foo', ), ); var_dump(json_encode($var));

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.0000.01418.43
8.3.50.0140.00521.08
8.3.40.0110.00418.79
8.3.30.0070.00718.62
8.3.20.0050.00318.80
8.3.10.0060.00320.36
8.3.00.0080.00021.94
8.2.180.0150.00617.00
8.2.170.0140.00322.96
8.2.160.0030.01020.52
8.2.150.0100.00624.18
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0060.00319.36
8.2.110.0070.00422.12
8.2.100.0070.00418.01
8.2.90.0030.00619.17
8.2.80.0000.00918.03
8.2.70.0060.00317.63
8.2.60.0090.00018.04
8.2.50.0000.00818.07
8.2.40.0040.00418.34
8.2.30.0000.00919.75
8.2.20.0000.00817.70
8.2.10.0030.00617.77
8.2.00.0000.00817.87
8.1.280.0120.00625.92
8.1.270.0040.00423.99
8.1.260.0040.01426.35
8.1.250.0080.00028.09
8.1.240.0080.00420.82
8.1.230.0000.01221.00
8.1.220.0050.00318.77
8.1.210.0030.00518.97
8.1.200.0040.00417.48
8.1.190.0040.00417.53
8.1.180.0090.00018.10
8.1.170.0000.00918.97
8.1.160.0040.00419.04
8.1.150.0050.00218.71
8.1.140.0040.00417.45
8.1.130.0000.00717.89
8.1.120.0040.00417.43
8.1.110.0000.00717.50
8.1.100.0040.00417.37
8.1.90.0040.00417.52
8.1.80.0080.00017.53
8.1.70.0030.00317.41
8.1.60.0000.00817.70
8.1.50.0040.00417.46
8.1.40.0000.00817.55
8.1.30.0000.00817.66
8.1.20.0040.00417.66
8.1.10.0000.00817.66
8.1.00.0000.00717.53
8.0.300.0060.00320.02
8.0.290.0000.00816.75
8.0.280.0030.00318.50
8.0.270.0000.00717.32
8.0.260.0030.00316.98
8.0.250.0070.00016.98
8.0.240.0060.00317.11
8.0.230.0030.00317.14
8.0.220.0040.00417.09
8.0.210.0040.00417.04
8.0.200.0030.00317.07
8.0.190.0000.00817.10
8.0.180.0040.00417.04
8.0.170.0000.00716.95
8.0.160.0000.00717.07
8.0.150.0030.00616.93
8.0.140.0080.00316.82
8.0.130.0050.00013.44
8.0.120.0080.00016.86
8.0.110.0000.00816.90
8.0.100.0090.00016.84
8.0.90.0000.00717.00
8.0.80.0030.01316.90
8.0.70.0070.00016.98
8.0.60.0040.00417.05
8.0.50.0040.00416.99
8.0.30.0160.00517.19
8.0.20.0170.00517.40
8.0.10.0040.00417.21
8.0.00.0100.00816.92
7.4.330.0000.00713.43
7.4.320.0060.00016.50
7.4.300.0000.00616.73
7.4.290.0000.00716.57
7.4.280.0040.00416.57
7.4.270.0000.00816.59
7.4.260.0050.00013.32
7.4.250.0000.00816.67
7.4.240.0000.00916.68
7.4.230.0000.00716.66
7.4.220.0030.01616.45
7.4.210.0080.00716.58
7.4.200.0070.00016.56
7.4.190.0040.00416.83
7.4.160.0120.00316.56
7.4.150.0120.00617.40
7.4.140.0080.01317.86
7.4.130.0060.01316.57
7.4.120.0070.01016.64
7.4.110.0170.00016.52
7.4.100.0090.01216.45
7.4.90.0090.00916.75
7.4.80.0070.01119.04
7.4.70.0130.00416.62
7.4.60.0030.01316.38
7.4.50.0060.00316.73
7.4.40.0030.01322.27
7.4.30.0030.01716.45
7.4.00.0040.01415.25
7.3.330.0020.00213.27
7.3.320.0030.00313.31
7.3.310.0060.00316.46
7.3.300.0040.00416.36
7.3.290.0040.01116.41
7.3.280.0080.00616.37
7.3.270.0100.01517.40
7.3.260.0090.00918.24
7.3.250.0140.00616.37
7.3.240.0120.00916.59
7.3.230.0070.01116.64
7.3.210.0160.00016.45
7.3.200.0120.00619.39
7.3.190.0060.01316.31
7.3.180.0060.01016.31
7.3.170.0100.00616.27
7.3.160.0100.00716.23
7.3.120.0100.00614.79
7.2.330.0100.00716.59
7.2.320.0140.00416.46
7.2.310.0040.01516.55
7.2.300.0130.00316.65
7.2.290.0080.00816.49
7.2.00.0060.01319.35
7.1.100.0060.00918.21
7.1.70.0000.00816.89
7.1.60.0110.00719.40
7.1.50.0060.01816.73
7.1.00.0030.06722.57
7.0.200.0000.00716.74
7.0.140.0000.07322.00
7.0.110.0000.04320.03
7.0.100.0000.04720.02
7.0.90.0100.08020.00
7.0.80.0070.04020.06
7.0.70.0100.04020.10
7.0.60.0030.04320.02
7.0.50.0170.03720.02
7.0.40.0030.04019.83
7.0.30.0000.04719.86
7.0.20.0100.03719.73
7.0.10.0000.04319.64
7.0.00.0000.04719.74
5.6.280.0030.07321.11
5.6.260.0130.03020.61
5.6.250.0100.07020.64
5.6.240.0030.08020.60
5.6.230.0100.04320.70
5.6.220.0000.04320.70
5.6.210.0100.03320.72
5.6.200.0030.04020.59
5.6.190.0100.03720.68
5.6.180.0030.04020.71
5.6.170.0070.04020.66
5.6.160.0030.06020.64
5.6.150.0070.04020.48
5.6.140.0030.04020.68
5.6.130.0070.03720.63
5.6.120.0000.04320.48
5.6.110.0100.04020.63
5.6.100.0070.04320.63
5.6.90.0030.03720.68
5.6.80.0100.04020.11
5.6.70.0030.03719.98
5.6.60.0100.06020.07
5.6.50.0030.08020.10
5.6.40.0100.04320.01
5.6.30.0100.03019.94
5.6.20.0030.07319.93
5.6.10.0170.06720.05
5.6.00.0130.04019.93
5.5.380.0070.07717.54
5.5.370.0030.04717.61
5.5.360.0070.04717.68
5.5.350.0070.03717.57
5.5.340.0000.04317.83
5.5.330.0070.03718.05
5.5.320.0100.04018.07
5.5.310.0030.04718.09
5.5.300.0100.03317.93
5.5.290.0100.03718.07
5.5.280.0030.04018.09
5.5.270.0030.04018.04
5.5.260.0030.04718.07
5.5.250.0100.04718.04
5.5.240.0100.03317.32
5.5.230.0000.03317.43
5.5.220.0030.04317.50
5.5.210.0030.04017.48
5.5.200.0070.07017.58
5.5.190.0030.08017.27
5.5.180.0130.04017.55
5.5.160.0030.08317.48
5.5.150.0170.06717.40
5.5.140.0030.07717.44
5.5.130.0170.07017.28
5.5.120.0100.04317.57
5.5.110.0070.04717.26
5.5.100.0070.07717.46
5.5.90.0070.08017.36
5.5.80.0030.06717.35
5.5.70.0130.07017.32
5.5.60.0070.07017.37
5.5.50.0130.07317.50
5.5.40.0100.07017.38
5.5.30.0170.06317.34
5.5.20.0030.08717.19
5.5.10.0100.05317.17
5.5.00.0130.07017.08
5.4.450.0030.04019.64
5.4.440.0030.04319.50
5.4.430.0000.04319.46
5.4.420.0030.04019.35
5.4.410.0000.03319.19
5.4.400.0070.04719.23
5.4.390.0000.04319.01
5.4.380.0100.05019.01
5.4.370.0070.03319.00
5.4.360.0070.05319.09
5.4.350.0170.08019.22
5.4.340.0130.06319.07
5.4.320.0130.07019.01
5.4.310.0100.06719.01
5.4.300.0100.06319.00
5.4.290.0100.07319.14
5.4.280.0130.05719.09
5.4.270.0100.07019.30
5.4.260.0030.07719.01
5.4.250.0070.07318.95
5.4.240.0100.04719.00
5.4.230.0000.05019.00
5.4.220.0030.07719.08
5.4.210.0100.06719.13
5.4.200.0030.08019.31
5.4.190.0030.07319.32
5.4.180.0030.07319.02
5.4.170.0070.06318.95
5.4.160.0200.06719.27
5.4.150.0030.08019.07
5.4.140.0070.07316.39
5.4.130.0030.07316.60
5.4.120.0070.05016.59
5.4.110.0070.06716.46
5.4.100.0030.08316.52
5.4.90.0070.06016.56
5.4.80.0130.03016.71
5.4.70.0070.07016.61
5.4.60.0030.05716.57
5.4.50.0070.04016.48
5.4.40.0100.05316.68
5.4.30.0000.06316.45
5.4.20.0070.06716.42
5.4.10.0030.04016.54
5.4.00.0030.06315.82
5.3.290.0030.07714.71
5.3.280.0070.05714.62
5.3.270.0170.07014.72
5.3.260.0070.08314.71
5.3.250.0100.06314.78
5.3.240.0130.06714.71
5.3.230.0130.03014.77
5.3.220.0070.07314.63
5.3.210.0100.07014.61
5.3.200.0070.07714.45
5.3.190.0100.07014.59
5.3.180.0130.06714.68
5.3.170.0100.05314.72
5.3.160.0000.06714.71
5.3.150.0030.04714.60
5.3.140.0130.05314.60
5.3.130.0070.07014.56
5.3.120.0000.08014.66
5.3.110.0070.08014.66
5.3.100.0030.07714.20
5.3.90.0030.07714.18
5.3.80.0070.06714.02
5.3.70.0030.06714.07
5.3.60.0070.03014.04
5.3.50.0070.06014.06
5.3.40.0130.07014.20
5.3.30.0100.06714.00
5.3.20.0100.05013.95
5.3.10.0030.07013.66
5.3.00.0030.07713.74
5.2.170.0100.05311.91
5.2.160.0030.04011.91
5.2.150.0030.06011.91
5.2.140.0000.06711.91
5.2.130.0000.03311.91
5.2.120.0070.06011.91
5.2.110.0030.06011.91
5.2.100.0030.06011.91
5.2.90.0030.04311.91
5.2.80.0070.04711.91
5.2.70.0070.04011.91
5.2.60.0070.05311.91
5.2.50.0000.03711.91
5.2.40.0070.06011.91
5.2.30.0030.05711.91
5.2.20.0000.04011.91
5.2.10.0070.06711.91
5.2.00.0000.06711.91
5.1.60.0000.05711.91
5.1.50.0000.04011.91
5.1.40.0100.04711.91
5.1.30.0000.05011.91
5.1.20.0130.03711.91
5.1.10.0100.04711.91
5.1.00.0030.05711.91
5.0.50.0000.04711.91
5.0.40.0030.04011.91
5.0.30.0030.06011.91
5.0.20.0030.04011.91
5.0.10.0030.02311.91
5.0.00.0000.05311.91
4.4.90.0030.02311.91
4.4.80.0030.03311.91
4.4.70.0070.02711.91
4.4.60.0000.03311.91
4.4.50.0000.03711.91
4.4.40.0000.05311.91
4.4.30.0000.03711.91
4.4.20.0000.03711.91
4.4.10.0030.03711.91
4.4.00.0030.05011.91
4.3.110.0000.03711.91
4.3.100.0030.01311.91
4.3.90.0000.02011.91
4.3.80.0000.02711.91
4.3.70.0000.03011.91
4.3.60.0000.01711.91
4.3.50.0030.02711.91
4.3.40.0070.04711.91
4.3.30.0000.01711.91
4.3.20.0000.03711.91
4.3.10.0030.02311.91
4.3.00.0000.03011.91

preferences:
58.25 ms | 401 KiB | 5 Q