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 = '"'. addcslashes($k, '"\\') . '"'; $data[] = $k . ':' . $v; } else { $data[] = $v; } } if ($assoc) { $spl = '{'; $spr = '}'; } else { $spl = '['; $spr = ']'; } return $spl . implode(',', $data) . $spr; } 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) { $pattern = "/\r|(\n)|((?:[^\x09\x0A\x0D\x20-\x7E]{3})+)/"; return preg_replace_callback($pattern, '_js_uc_esc_cb', $value); } function _js_uc_esc_cb($matches) { switch (true) { case isset($matches[2]): $char = mb_convert_encoding($matches[2], '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; case isset($matches[1]): return '\\n'; default: return '\\r'; } } } $var = array( array( 'text', 1, 1.1, true, false, null, array(), new stdClass, fopen('php://stdin', 'r'), ), 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.0160.00616.63
8.3.50.0040.01117.92
8.3.40.0070.00718.73
8.3.30.0140.00018.96
8.3.20.0000.00820.06
8.3.10.0080.00023.61
8.3.00.0040.00419.26
8.2.180.0040.01116.75
8.2.170.0120.00322.96
8.2.160.0140.00020.41
8.2.150.0040.00424.18
8.2.140.0030.00724.66
8.2.130.0120.00326.16
8.2.120.0000.00822.10
8.2.110.0030.00622.08
8.2.100.0100.00317.91
8.2.90.0090.00019.35
8.2.80.0040.00418.05
8.2.70.0000.00917.63
8.2.60.0040.00418.04
8.2.50.0070.00418.07
8.2.40.0050.00318.16
8.2.30.0080.00018.04
8.2.20.0000.00917.73
8.2.10.0040.00418.00
8.2.00.0040.00417.80
8.1.270.0080.00022.32
8.1.260.0130.00326.35
8.1.250.0080.00028.09
8.1.240.0040.00423.79
8.1.230.0080.00319.10
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0040.00417.65
8.1.180.0090.00018.10
8.1.170.0000.00918.68
8.1.160.0040.00422.02
8.1.150.0040.00418.70
8.1.140.0040.00417.43
8.1.130.0000.00717.84
8.1.120.0040.00417.56
8.1.110.0000.00817.56
8.1.100.0050.00317.52
8.1.90.0030.00517.42
8.1.80.0040.00417.41
8.1.70.0000.00717.40
8.1.60.0060.00317.52
8.1.50.0050.00317.48
8.1.40.0040.00417.51
8.1.30.0080.00017.64
8.1.20.0040.00417.69
8.1.10.0000.00717.55
8.1.00.0030.00617.51
8.0.300.0000.00718.77
8.0.290.0040.00417.41
8.0.280.0030.00318.56
8.0.270.0000.00717.41
8.0.260.0030.00317.08
8.0.250.0050.00217.19
8.0.240.0050.00317.15
8.0.230.0000.00717.01
8.0.220.0040.00417.12
8.0.210.0040.00417.10
8.0.200.0060.00017.19
8.0.190.0030.00617.22
8.0.180.0000.00717.12
8.0.170.0000.00817.04
8.0.160.0040.00417.10
8.0.150.0040.00417.11
8.0.140.0040.00417.00
8.0.130.0000.00613.50
8.0.120.0030.00517.07
8.0.110.0040.00417.00
8.0.100.0000.00817.07
8.0.90.0030.00516.96
8.0.80.0070.01417.06
8.0.70.0050.00317.02
8.0.60.0020.00516.98
8.0.50.0000.00817.12
8.0.30.0130.00817.09
8.0.20.0120.00917.40
8.0.10.0050.00316.96
8.0.00.0120.00516.96
7.4.330.0000.00515.20
7.4.320.0000.00616.64
7.4.300.0080.00016.56
7.4.290.0040.00416.52
7.4.280.0000.00716.64
7.4.270.0030.00316.68
7.4.260.0030.00516.64
7.4.250.0060.00316.66
7.4.240.0020.00516.61
7.4.230.0000.00716.39
7.4.220.0070.01116.62
7.4.210.0110.00616.69
7.4.200.0000.00716.38
7.4.190.0040.00416.82
7.4.160.0080.00816.64
7.4.150.0080.00917.40
7.4.140.0120.00617.86
7.4.130.0080.00916.73
7.4.120.0060.01116.54
7.4.110.0120.00616.61
7.4.100.0140.00716.70
7.4.90.0090.00916.47
7.4.80.0060.01219.39
7.4.70.0130.00616.61
7.4.60.0090.00616.52
7.4.50.0060.00316.36
7.4.40.0060.00622.77
7.4.30.0150.00716.58
7.4.00.0030.00715.11
7.3.330.0000.00613.50
7.3.320.0030.00313.40
7.3.310.0030.00316.41
7.3.300.0070.00016.47
7.3.290.0130.00416.43
7.3.280.0130.00516.37
7.3.270.0070.01117.40
7.3.260.0040.02016.58
7.3.250.0160.00616.44
7.3.240.0100.01016.52
7.3.230.0110.00516.40
7.3.210.0090.00916.34
7.3.200.0130.00919.39
7.3.190.0030.01716.39
7.3.180.0000.01616.40
7.3.170.0030.01416.46
7.3.160.0050.01116.62
7.3.120.0050.00814.69
7.3.110.0110.00414.92
7.3.100.0120.00314.70
7.3.90.0100.00714.80
7.3.80.0030.00914.72
7.3.70.0090.00314.99
7.3.60.0060.00914.74
7.3.50.0070.01014.67
7.3.40.0030.00614.89
7.3.30.0040.00814.85
7.3.20.0130.00016.46
7.3.10.0040.00716.62
7.3.00.0030.00816.56
7.2.330.0090.01016.66
7.2.320.0190.00316.47
7.2.310.0100.00716.66
7.2.300.0100.00716.52
7.2.290.0080.01116.71
7.2.240.0030.01615.27
7.2.230.0060.00614.75
7.2.220.0000.01415.05
7.2.210.0000.00814.98
7.2.200.0040.00814.96
7.2.190.0090.00015.14
7.2.180.0090.00914.90
7.2.170.0030.00914.94
7.2.160.0070.00314.69
7.2.150.0000.01416.99
7.2.140.0000.01316.98
7.2.130.0030.01016.88
7.2.120.0070.00616.73
7.2.110.0100.00417.01
7.2.100.0100.00416.85
7.2.90.0100.00516.93
7.2.80.0080.00716.90
7.2.70.0080.00816.93
7.2.60.0060.00716.90
7.2.50.0060.00816.81
7.2.40.0060.00517.02
7.2.30.0090.00217.01
7.2.20.0020.01116.95
7.2.10.0110.00316.83
7.2.00.0060.00717.86
7.1.330.0150.00415.81
7.1.320.0030.00615.80
7.1.310.0030.00615.85
7.1.300.0120.00315.68
7.1.290.0030.00615.84
7.1.280.0080.00415.79
7.1.270.0070.00715.43
7.1.260.0060.00915.68
7.1.250.0050.00715.85
7.1.100.0030.00917.95
7.1.70.0000.00917.25
7.1.60.0060.01219.33
7.1.50.0030.01716.89
7.1.00.0070.07322.45
7.0.200.0030.01016.79
7.0.140.0100.06721.97
7.0.90.0100.05019.88
7.0.80.0200.03719.91
7.0.70.0230.03719.89
7.0.60.0230.03320.00
7.0.50.0270.03020.30
7.0.40.0070.03020.03
7.0.30.0000.04019.95
7.0.20.0030.03720.08
7.0.10.0070.06320.07
7.0.00.0000.04020.16
5.6.280.0000.07721.11
5.6.240.0070.04020.53
5.6.230.0100.05020.52
5.6.220.0030.03720.73
5.6.210.0000.03720.63
5.6.200.0030.03721.11
5.6.190.0000.03721.12
5.6.180.0000.03721.08
5.6.170.0070.06721.06
5.6.160.0170.07321.08
5.6.150.0070.07021.06
5.6.140.0100.07320.97
5.6.130.0000.03721.03
5.6.120.0100.04321.08
5.6.110.0100.04321.15
5.6.100.0030.07721.09
5.6.90.0100.03021.04
5.6.80.0030.05720.46
5.6.70.0030.07320.41
5.6.60.0000.03720.47
5.6.50.0000.03720.35
5.6.40.0000.03720.48
5.6.30.0000.03720.40
5.6.20.0030.04720.41
5.6.10.0070.05720.40
5.6.00.0100.06720.38
5.5.380.0030.04020.51
5.5.370.0030.04020.37
5.5.360.0070.03020.38
5.5.350.0030.03720.44
5.5.340.0030.03720.94
5.5.330.0030.03320.82
5.5.320.0000.03720.91
5.5.310.0030.03720.66
5.5.300.0070.04020.75
5.5.290.0000.04020.92
5.5.280.0030.03720.88
5.5.270.0100.07020.91
5.5.260.0070.04320.77
5.5.250.0030.05320.73
5.5.240.0100.06720.24
5.5.230.0100.03720.30
5.5.220.0030.03320.17
5.5.210.0200.06320.17
5.5.200.0030.06320.23
5.5.190.0070.03320.25
5.5.180.0000.03720.21
5.5.160.0170.05020.19
5.5.150.0070.03020.23
5.5.140.0100.04720.10
5.5.130.0070.04320.14
5.5.120.0130.04320.19
5.5.110.0070.07720.21
5.5.100.0070.03020.18
5.5.90.0000.03720.11
5.5.80.0000.08320.09
5.5.70.0000.04320.14
5.5.60.0030.04020.12
5.5.50.0170.02020.03
5.5.40.0100.06720.13
5.5.30.0030.03320.14
5.5.20.0070.08020.01
5.5.10.0070.07720.13
5.5.00.0000.08320.14
5.4.450.0070.06319.24
5.4.440.0070.03019.36
5.4.430.0070.05719.48
5.4.420.0030.04019.50
5.4.410.0130.02719.36
5.4.400.0000.03719.13
5.4.390.0100.06719.05
5.4.380.0130.05019.13
5.4.370.0100.06719.21
5.4.360.0070.03019.03
5.4.350.0030.03319.05
5.4.340.0030.07319.03
5.4.320.0070.07018.87
5.4.310.0100.05319.13
5.4.300.0030.03318.89
5.4.290.0030.06019.18
5.4.280.0070.04319.04
5.4.270.0030.08719.13
5.4.260.0070.03018.92
5.4.250.0170.06718.87
5.4.240.0130.07018.90
5.4.230.0100.04318.94
5.4.220.0030.03318.89
5.4.210.0070.05319.07
5.4.200.0070.07018.91
5.4.190.0070.02719.17
5.4.180.0100.04319.17
5.4.170.0100.03019.21
5.4.160.0130.06719.16
5.4.150.0130.06019.03
5.4.140.0000.03316.44
5.4.130.0000.04016.41
5.4.120.0000.04016.34
5.4.110.0070.07316.55
5.4.100.0070.05316.40
5.4.90.0070.07316.43
5.4.80.0100.06316.48
5.4.70.0000.05016.47
5.4.60.0070.04016.48
5.4.50.0070.06316.26
5.4.40.0100.07016.52
5.4.30.0070.04316.44
5.4.20.0130.03016.26
5.4.10.0000.05016.48
5.4.00.0030.06315.60
5.3.290.0030.04714.76
5.3.280.0030.04314.55
5.3.270.0070.05314.57
5.3.260.0030.07714.58
5.3.250.0070.03014.61
5.3.240.0070.03314.69
5.3.230.0070.06314.69
5.3.220.0030.08714.57
5.3.210.0030.05314.70
5.3.200.0030.07314.54
5.3.190.0070.08014.60
5.3.180.0070.04714.60
5.3.170.0070.07714.61
5.3.160.0100.03314.71
5.3.150.0030.04014.61
5.3.140.0070.05314.51
5.3.130.0130.07014.64
5.3.120.0130.07314.70
5.3.110.0030.07014.61
5.3.100.0100.05014.12
5.3.90.0070.06314.04
5.3.80.0100.07014.16
5.3.70.0030.04314.03
5.3.60.0100.05714.09
5.3.50.0030.04013.90
5.3.40.0100.06714.09
5.3.30.0170.06013.88
5.3.20.0200.05013.84
5.3.10.0130.06713.66
5.3.00.0100.03313.65
5.2.170.0100.07711.32
5.2.160.0200.04011.06
5.2.150.0070.04311.09
5.2.140.0070.06711.31
5.2.130.0130.05311.05
5.2.120.0100.06711.28
5.2.110.0100.06311.23
5.2.100.0000.03311.25
5.2.90.0070.05311.24
5.2.80.0030.06311.05
5.2.70.0070.04711.26
5.2.60.0030.03311.14
5.2.50.0000.06711.17
5.2.40.0070.03710.94
5.2.30.0070.05711.02
5.2.20.0030.06311.05
5.2.10.0100.03010.80
5.2.00.0000.03010.86
5.1.60.0030.02310.05
5.1.50.0030.02710.11
5.1.40.0000.02710.09
5.1.30.0100.04710.43
5.1.20.0030.02710.41
5.1.10.0070.02710.15
5.1.00.0070.02310.11
5.0.50.0030.0208.46
5.0.40.0000.0178.59
5.0.30.0070.0538.28
5.0.20.0030.0138.14
5.0.10.0000.0178.30
5.0.00.0070.0238.21
4.4.90.0000.0307.30
4.4.80.0030.0137.30
4.4.70.0070.0277.30
4.4.60.0030.0237.30
4.4.50.0000.0207.30
4.4.40.0000.0277.30
4.4.30.0000.0277.30
4.4.20.0000.0277.30
4.4.10.0000.0177.30
4.4.00.0000.0337.30
4.3.110.0000.0137.30
4.3.100.0030.0107.30
4.3.90.0000.0137.30
4.3.80.0000.0207.30
4.3.70.0030.0337.30
4.3.60.0000.0237.30
4.3.50.0000.0177.30
4.3.40.0000.0277.30
4.3.30.0000.0307.30
4.3.20.0000.0177.30
4.3.10.0000.0177.30
4.3.00.0000.0377.30

preferences:
58.44 ms | 400 KiB | 5 Q