3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('json_encode')) { function json_encode($it) { $tmp = $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 !_js_check_utf8($value): case $value === null: case is_resource($value): return 'null'; case is_bool($value): return $value ? 'true' : 'false'; case is_string($value): return '"' . _js_uc_esc($value) . '"'; default: return $value; } } function _js_uc_esc($value) { $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\\\"/"); } } } $var = array( array( 'text', 1, 1.1, true, false, null, array(), new stdClass, fopen('php://stdin', 'r'), ), array("" => "hoge"), 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.0100.01418.33
8.3.50.0100.00822.05
8.3.40.0040.01418.97
8.3.30.0070.01318.93
8.3.20.0040.00418.95
8.3.10.0090.00020.97
8.3.00.0050.00321.87
8.2.180.0120.00316.63
8.2.170.0090.00622.96
8.2.160.0100.00320.47
8.2.150.0000.00824.18
8.2.140.0040.01124.66
8.2.130.0040.00426.16
8.2.120.0040.00420.95
8.2.110.0090.00020.30
8.2.100.0040.00717.84
8.2.90.0040.00419.17
8.2.80.0000.00817.97
8.2.70.0050.00317.63
8.2.60.0000.00817.80
8.2.50.0060.00318.07
8.2.40.0040.00418.18
8.2.30.0050.00521.20
8.2.20.0050.00217.78
8.2.10.0040.00417.70
8.2.00.0030.00517.88
8.1.280.0070.01125.92
8.1.270.0040.00423.99
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0030.00622.55
8.1.230.0090.00320.75
8.1.220.0080.00018.77
8.1.210.0080.00018.86
8.1.200.0030.00617.48
8.1.190.0040.00417.63
8.1.180.0040.00418.10
8.1.170.0000.00818.78
8.1.160.0060.00318.97
8.1.150.0050.00318.58
8.1.140.0060.00317.44
8.1.130.0030.00317.95
8.1.120.0030.00717.58
8.1.110.0030.00517.50
8.1.100.0040.00417.44
8.1.90.0040.00417.53
8.1.80.0000.00817.36
8.1.70.0000.00817.41
8.1.60.0000.00917.58
8.1.50.0080.00017.57
8.1.40.0020.00517.62
8.1.30.0040.00417.60
8.1.20.0030.00517.75
8.1.10.0040.00417.71
8.1.00.0030.00617.46
8.0.300.0090.00020.11
8.0.290.0030.00617.43
8.0.280.0040.00418.58
8.0.270.0040.00417.50
8.0.260.0040.00417.07
8.0.250.0000.00717.20
8.0.240.0070.00317.19
8.0.230.0030.00317.08
8.0.220.0000.00716.98
8.0.210.0070.00017.05
8.0.200.0070.00017.13
8.0.190.0050.00317.07
8.0.180.0000.00917.03
8.0.170.0060.00317.20
8.0.160.0030.00417.05
8.0.150.0000.00817.03
8.0.140.0030.00717.07
8.0.130.0000.00613.48
8.0.120.0000.00716.96
8.0.110.0040.00417.09
8.0.100.0070.00016.89
8.0.90.0070.00016.96
8.0.80.0040.01117.08
8.0.70.0000.00916.91
8.0.60.0040.00417.20
8.0.50.0040.00416.97
8.0.30.0130.00817.13
8.0.20.0090.01317.40
8.0.10.0000.00717.02
8.0.00.0110.00616.93
7.4.330.0000.00514.75
7.4.320.0000.00616.59
7.4.300.0030.00316.53
7.4.290.0030.00316.68
7.4.280.0030.00316.66
7.4.270.0030.00316.69
7.4.260.0000.00513.31
7.4.250.0000.00816.66
7.4.240.0050.00316.69
7.4.230.0040.00416.48
7.4.220.0110.00716.61
7.4.210.0040.01216.65
7.4.200.0050.00216.68
7.4.190.0030.00316.84
7.4.160.0100.00616.45
7.4.150.0080.01117.40
7.4.140.0100.00817.86
7.4.130.0080.01316.55
7.4.120.0100.00816.61
7.4.110.0070.01716.63
7.4.100.0100.00716.55
7.4.90.0100.00716.57
7.4.80.0070.01019.39
7.4.70.0120.00316.49
7.4.60.0230.00016.65
7.4.50.0040.00416.52
7.4.40.0120.00322.52
7.4.30.0030.01316.51
7.4.00.0060.01015.04
7.3.330.0050.00013.37
7.3.320.0030.00313.43
7.3.310.0030.00316.44
7.3.300.0070.00016.43
7.3.290.0130.00316.48
7.3.280.0110.00616.45
7.3.270.0180.00017.40
7.3.260.0090.00918.24
7.3.250.0090.00816.40
7.3.240.0140.00316.30
7.3.230.0100.00916.66
7.3.210.0100.00616.36
7.3.200.0190.00819.39
7.3.190.0000.01716.35
7.3.180.0090.00616.43
7.3.170.0070.01016.60
7.3.160.0070.01016.33
7.3.120.0060.00914.61
7.3.110.0060.01215.02
7.3.100.0000.01415.05
7.3.90.0000.01014.61
7.3.80.0100.00314.79
7.3.70.0030.00914.89
7.3.60.0060.00614.88
7.3.50.0070.00714.91
7.3.40.0070.00714.71
7.3.30.0070.01115.02
7.3.20.0060.00616.50
7.3.10.0060.00816.48
7.3.00.0100.00716.42
7.2.330.0090.00916.38
7.2.320.0120.00816.71
7.2.310.0060.01216.54
7.2.300.0030.01316.45
7.2.290.0200.00016.48
7.2.250.0080.00815.02
7.2.240.0030.01415.20
7.2.230.0090.00915.11
7.2.220.0040.01114.87
7.2.210.0030.01314.97
7.2.200.0120.00314.69
7.2.190.0000.00914.92
7.2.180.0030.01014.81
7.2.170.0100.00715.11
7.2.60.0110.00016.86
7.2.50.0040.01116.83
7.1.330.0040.01115.68
7.1.320.0100.00315.81
7.1.310.0000.01315.90
7.1.300.0040.00415.59
7.1.290.0080.00915.60
7.1.280.0050.00515.67
7.1.270.0040.01115.67
7.1.260.0060.00615.50
7.1.200.0090.00615.53
7.1.70.0030.01216.80
7.1.60.0100.01419.40
7.1.50.0140.01016.89
7.1.00.0000.03722.54
7.0.200.0030.00616.92
7.0.140.0130.05722.00
7.0.90.0330.07719.95
7.0.80.0670.07020.05
7.0.70.0670.05020.05
7.0.60.0670.07719.99
7.0.50.0530.08020.34
7.0.40.0130.04020.15
7.0.30.0100.08020.14
7.0.20.0070.06320.11
7.0.10.0030.07720.16
7.0.00.0030.05020.10
5.6.280.0070.07021.08
5.6.240.0100.08720.68
5.6.230.0130.08020.59
5.6.220.0200.06720.62
5.6.210.0030.08320.79
5.6.200.0100.08020.96
5.6.190.0100.04721.05
5.6.180.0200.06321.03
5.6.170.0130.05021.06
5.6.160.0200.06721.04
5.6.150.0070.07320.93
5.6.140.0130.07021.11
5.6.130.0030.08721.03
5.6.120.0170.07721.18
5.6.110.0230.06721.03
5.6.100.0070.08021.08
5.6.90.0100.07721.14
5.6.80.0100.04320.46
5.6.70.0100.05320.48
5.6.60.0030.08020.44
5.6.50.0130.07320.57
5.6.40.0100.07020.42
5.6.30.0170.04720.55
5.6.20.0130.05020.30
5.6.10.0070.05020.40
5.6.00.0070.07720.29
5.5.380.0200.07020.55
5.5.370.0070.07720.46
5.5.360.0100.07720.37
5.5.350.0070.08020.43
5.5.340.0070.04320.80
5.5.330.0130.07020.82
5.5.320.0170.05020.81
5.5.310.0100.06720.94
5.5.300.0100.05320.90
5.5.290.0130.07020.78
5.5.280.0130.08320.93
5.5.270.0170.07320.77
5.5.260.0130.08020.90
5.5.250.0130.07020.62
5.5.240.0100.08020.20
5.5.230.0170.06020.13
5.5.220.0170.07320.30
5.5.210.0030.08020.33
5.5.200.0070.05320.24
5.5.190.0100.05320.13
5.5.180.0070.04320.01
5.5.160.0030.08020.27
5.5.150.0070.05720.12
5.5.140.0030.08720.25
5.5.130.0030.07720.22
5.5.120.0170.07320.23
5.5.110.0030.08320.25
5.5.100.0130.03720.00
5.5.90.0030.04720.09
5.5.80.0000.07720.08
5.5.70.0100.06020.08
5.5.60.0030.06719.95
5.5.50.0100.07019.95
5.5.40.0070.07720.07
5.5.30.0100.04320.07
5.5.20.0130.04020.13
5.5.10.0100.07020.13
5.5.00.0100.04720.04
5.4.450.0130.07319.28
5.4.440.0170.07719.41
5.4.430.0030.07319.19
5.4.420.0100.04319.55
5.4.410.0070.07019.34
5.4.400.0100.07719.03
5.4.390.0070.04319.05
5.4.380.0070.07319.05
5.4.370.0030.06318.85
5.4.360.0130.07019.12
5.4.350.0070.06719.09
5.4.340.0130.06018.91
5.4.320.0100.07719.21
5.4.310.0130.04718.87
5.4.300.0200.06319.12
5.4.290.0100.07019.04
5.4.280.0100.07018.84
5.4.270.0100.07718.87
5.4.260.0070.07719.09
5.4.250.0000.08319.04
5.4.240.0000.07719.02
5.4.230.0070.04719.10
5.4.220.0100.07719.12
5.4.210.0130.06319.12
5.4.200.0100.06318.87
5.4.190.0070.06318.89
5.4.180.0100.07718.89
5.4.170.0100.06719.07
5.4.160.0000.08319.05
5.4.150.0100.07319.14
5.4.140.0070.07316.34
5.4.130.0030.05016.41
5.4.120.0070.04316.34
5.4.110.0000.07316.41
5.4.100.0030.04716.58
5.4.90.0170.06716.52
5.4.80.0130.03716.48
5.4.70.0130.06716.51
5.4.60.0100.06016.52
5.4.50.0100.07016.46
5.4.40.0200.04716.59
5.4.30.0100.04716.39
5.4.20.0130.06016.46
5.4.10.0130.06316.47
5.4.00.0130.04015.81
5.3.290.0000.04714.64
5.3.280.0030.04314.68
5.3.270.0070.04714.69
5.3.260.0100.07714.56
5.3.250.0070.07314.57
5.3.240.0030.08014.70
5.3.230.0100.07714.62
5.3.220.0030.07314.68
5.3.210.0030.04714.66
5.3.200.0130.04314.52
5.3.190.0000.05014.62
5.3.180.0170.02714.65
5.3.170.0000.07014.58
5.3.160.0070.07314.55
5.3.150.0030.04714.54
5.3.140.0030.05714.59
5.3.130.0100.07314.53
5.3.120.0130.06014.66
5.3.110.0100.05314.57
5.3.100.0030.08314.17
5.3.90.0030.08314.11
5.3.80.0130.06014.10
5.3.70.0070.07313.95
5.3.60.0130.06314.09
5.3.50.0030.04313.87
5.3.40.0100.06313.99
5.3.30.0070.05714.04
5.3.20.0030.08013.87
5.3.10.0070.03713.62
5.3.00.0130.03713.66
5.2.170.0070.06311.18
5.2.160.0200.05011.08
5.2.150.0030.03711.06
5.2.140.0000.03311.07
5.2.130.0130.05011.25
5.2.120.0030.04311.05
5.2.110.0030.03311.20
5.2.100.0100.02311.20
5.2.90.0070.02711.27
5.2.80.0030.05311.18
5.2.70.0030.03311.25
5.2.60.0030.04711.00
5.2.50.0000.06011.12
5.2.40.0030.06011.13
5.2.30.0030.06311.07
5.2.20.0070.05311.13
5.2.10.0000.06310.79
5.2.00.0100.03310.78
5.1.60.0070.05010.77
5.1.50.0030.04310.77
5.1.40.0070.05010.77
5.1.30.0100.04010.77
5.1.20.0030.05710.77
5.1.10.0070.05010.77
5.1.00.0030.03710.77
5.0.50.0070.03010.77
5.0.40.0030.03310.77
5.0.30.0100.05710.77
5.0.20.0100.03710.77
5.0.10.0000.04010.77
5.0.00.0100.03310.77
4.4.90.0000.03710.77
4.4.80.0000.03710.77
4.4.70.0030.01710.77
4.4.60.0000.03710.77
4.4.50.0100.02710.77
4.4.40.0000.05710.77
4.4.30.0030.02310.77
4.4.20.0030.03710.77
4.4.10.0000.04010.77
4.4.00.0000.05710.77
4.3.110.0030.03710.77
4.3.100.0030.02710.77
4.3.90.0030.03710.77
4.3.80.0030.02310.77
4.3.70.0030.03310.77
4.3.60.0070.03010.77
4.3.50.0070.03010.77
4.3.40.0070.05010.77
4.3.30.0000.03710.77
4.3.20.0000.02710.77
4.3.10.0000.03710.77
4.3.00.0000.03710.77

preferences:
41.85 ms | 401 KiB | 5 Q