3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('json_encode')) { function json_encode($it) { if (!is_array($it) && !is_object($it)) { return _js_enc_value($it); } $assoc = false; $i = 0; foreach ($it as $k => $v) { if ($k !== $i) { $assoc = true; break; } $i++; } if (!isset($k)) { $assoc = true; } $data = array(); foreach ($it as $k => $v) { $k = '"'. addcslashes($k, '"\\') . '"'; $v = _js_enc_value($v); $data[] = $assoc ? $k . ':' . $v : $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): return 'null'; case is_string($value): return '"' . _js_uc_esc($value) . '"'; default: return $value; } } 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( 0 => array('text', 1, 1.1, true, false, null, new stdClass, (object)array(0 => 1)), 2 => array('a' => 'hoge', 'b' => 'foo'), ); $f = json_encode($var); var_dump(json_decode($f));

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.0070.01016.88
8.3.50.0150.00316.47
8.3.40.0150.00418.85
8.3.30.0110.00818.84
8.3.20.0090.00018.90
8.3.10.0080.00018.73
8.3.00.0090.00019.15
8.2.180.0130.00916.63
8.2.170.0090.00622.96
8.2.160.0120.00318.82
8.2.150.0060.00324.18
8.2.140.0000.00824.66
8.2.130.0000.00726.16
8.2.120.0120.00620.77
8.2.110.0060.00322.25
8.2.100.0100.00018.22
8.2.90.0050.00318.00
8.2.80.0100.00318.66
8.2.70.0090.00017.71
8.2.60.0080.00017.93
8.2.50.0080.00018.07
8.2.40.0060.00318.28
8.2.30.0000.00917.85
8.2.20.0030.00617.70
8.2.10.0040.00417.92
8.2.00.0080.00317.90
8.1.280.0070.00725.92
8.1.270.0040.00423.99
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0110.00020.70
8.1.230.0090.00317.77
8.1.220.0000.00817.79
8.1.210.0040.00718.77
8.1.200.0030.00617.23
8.1.190.0080.00017.23
8.1.180.0080.00418.10
8.1.170.0040.00418.65
8.1.160.0070.00018.97
8.1.150.0040.00418.61
8.1.140.0040.00417.61
8.1.130.0000.00719.23
8.1.120.0040.00417.42
8.1.110.0000.00717.53
8.1.100.0040.00417.52
8.1.90.0000.00717.41
8.1.80.0080.00017.48
8.1.70.0000.00717.49
8.1.60.0000.00817.52
8.1.50.0050.00317.49
8.1.40.0040.00417.57
8.1.30.0000.00817.66
8.1.20.0030.00617.71
8.1.10.0030.00517.62
8.1.00.0060.00317.61
8.0.300.0000.00918.84
8.0.290.0080.00016.88
8.0.280.0000.00718.49
8.0.270.0040.00417.22
8.0.260.0070.00016.84
8.0.250.0050.00216.97
8.0.240.0000.00817.09
8.0.230.0070.00017.09
8.0.220.0000.00717.06
8.0.210.0030.00316.97
8.0.200.0040.00417.06
8.0.190.0000.00717.09
8.0.180.0000.00917.01
8.0.170.0040.00416.84
8.0.160.0000.00716.92
8.0.150.0000.00817.04
8.0.140.0050.00316.97
8.0.130.0000.00613.45
8.0.120.0030.00616.94
8.0.110.0030.00517.12
8.0.100.0040.00416.95
8.0.90.0040.00417.04
8.0.80.0040.01217.06
8.0.70.0080.00016.89
8.0.60.0030.00616.84
8.0.50.0080.00017.07
8.0.30.0160.00317.01
8.0.20.0120.00717.31
8.0.10.0050.00217.19
8.0.00.0110.01316.93
7.4.330.0000.00513.02
7.4.320.0030.00316.55
7.4.300.0000.00616.63
7.4.290.0030.00316.46
7.4.280.0040.00416.59
7.4.270.0030.00316.56
7.4.260.0030.00313.32
7.4.250.0040.00416.56
7.4.240.0000.00716.68
7.4.230.0080.00416.30
7.4.220.0160.00316.54
7.4.210.0100.01016.54
7.4.200.0000.00816.49
7.4.190.0040.00416.72
7.4.160.0100.00716.59
7.4.150.0060.01316.59
7.4.140.0240.00316.47
7.4.130.0040.01516.62
7.4.120.0130.00416.53
7.4.110.0100.01016.66
7.4.100.0140.00516.62
7.4.90.0040.01416.64
7.4.80.0060.01119.39
7.4.70.0030.01716.52
7.4.60.0030.01416.52
7.4.50.0060.00016.61
7.4.40.0060.00616.59
7.4.30.0150.01116.53
7.4.00.0030.01314.85
7.3.330.0060.00013.33
7.3.320.0030.00313.34
7.3.310.0000.00716.40
7.3.300.0000.00716.21
7.3.290.0080.00916.32
7.3.280.0090.00816.28
7.3.270.0090.00916.54
7.3.260.0080.01116.27
7.3.250.0120.01016.29
7.3.240.0080.01216.54
7.3.230.0180.00016.42
7.3.210.0090.00916.31
7.3.200.0060.01216.48
7.3.190.0090.00916.71
7.3.180.0240.00016.56
7.3.170.0070.01016.46
7.3.160.0060.01216.46
7.3.120.0130.00314.59
7.3.10.0050.00816.58
7.3.00.0030.00916.68
7.2.330.0040.01516.82
7.2.320.0070.01016.62
7.2.310.0160.00616.58
7.2.300.0090.00916.47
7.2.290.0150.00416.78
7.2.130.0040.00717.06
7.2.120.0050.00916.99
7.2.110.0080.00516.86
7.2.100.0030.00816.82
7.2.90.0070.00717.04
7.2.80.0090.00516.92
7.2.70.0080.00516.89
7.2.60.0040.01016.65
7.2.50.0090.00516.71
7.2.40.0100.00516.99
7.2.30.0090.01116.79
7.2.20.0080.00916.75
7.2.10.0030.01016.88
7.2.00.0090.00716.97
7.1.250.0040.00715.63
7.1.200.0000.01315.81
7.1.100.0570.00615.84
7.1.70.0000.00717.10
7.1.60.0120.01219.30
7.1.50.0060.01916.79
7.1.00.0000.03722.30
7.0.200.0040.00416.57
7.0.140.0000.08021.94
7.0.120.0070.07322.03
7.0.90.0630.08019.89
7.0.80.0430.08319.88
7.0.70.0600.07319.92
7.0.60.0600.09020.02
7.0.50.0630.05320.37
7.0.40.0070.08720.04
7.0.30.0100.08720.03
7.0.20.0100.09020.04
7.0.10.0170.07020.08
7.0.00.0030.08320.14
5.6.280.0100.07021.17
5.6.240.0100.06320.62
5.6.230.0130.07320.77
5.6.220.0030.04720.63
5.6.210.0130.07320.76
5.6.200.0130.08021.11
5.6.190.0170.05321.19
5.6.180.0170.06720.98
5.6.170.0170.07721.06
5.6.160.0070.08021.02
5.6.150.0100.05721.10
5.6.140.0170.03721.02
5.6.130.0100.08321.07
5.6.120.0100.07721.04
5.6.110.0000.06021.18
5.6.100.0070.04321.09
5.6.90.0100.06020.93
5.6.80.0030.08320.51
5.6.70.0130.07020.49
5.6.60.0030.08320.43
5.6.50.0070.05720.33
5.6.40.0070.05320.41
5.6.30.0030.06720.32
5.6.20.0100.04720.43
5.6.10.0000.04320.48
5.6.00.0000.04320.37
5.5.380.0070.08020.38
5.5.370.0070.08020.45
5.5.360.0100.07720.57
5.5.350.0100.05020.43
5.5.340.0130.07720.75
5.5.330.0100.08020.89
5.5.320.0070.08320.79
5.5.310.0130.07020.89
5.5.300.0070.04020.75
5.5.290.0070.04020.85
5.5.280.0070.09020.89
5.5.270.0030.07320.87
5.5.260.0170.06320.89
5.5.250.0030.08320.59
5.5.240.0070.04020.18
5.5.230.0170.07020.15
5.5.220.0100.06020.29
5.5.210.0030.04320.20
5.5.200.0070.07020.13
5.5.190.0100.03720.23
5.5.180.0030.04320.26
5.5.160.0030.04020.10
5.5.150.0030.04020.25
5.5.140.0070.03720.27
5.5.130.0000.04720.16
5.5.120.0100.06020.13
5.5.110.0130.06320.22
5.5.100.0030.05320.13
5.5.90.0030.06320.09
5.5.80.0130.03720.18
5.5.70.0070.04320.12
5.5.60.0000.05020.12
5.5.50.0070.04020.06
5.5.40.0070.04020.02
5.5.30.0070.05019.97
5.5.20.0070.04720.07
5.5.10.0030.04020.00
5.5.00.0070.04020.02
5.4.450.0130.07719.18
5.4.440.0070.08319.36
5.4.430.0000.06019.46
5.4.420.0100.08019.20
5.4.410.0030.08019.23
5.4.400.0070.07718.91
5.4.390.0130.06319.14
5.4.380.0070.05018.93
5.4.370.0070.04019.21
5.4.360.0070.06318.87
5.4.350.0070.07319.18
5.4.340.0030.04719.16
5.4.320.0000.04319.23
5.4.310.0100.03719.15
5.4.300.0070.03319.24
5.4.290.0030.04019.05
5.4.280.0070.04019.09
5.4.270.0070.07719.20
5.4.260.0070.03719.13
5.4.250.0070.04019.20
5.4.240.0070.03719.19
5.4.230.0070.03719.12
5.4.220.0030.04019.13
5.4.210.0070.03318.86
5.4.200.0100.03018.85
5.4.190.0070.04018.89
5.4.180.0000.04319.08
5.4.170.0030.04019.21
5.4.160.0030.04719.03
5.4.150.0030.04319.04
5.4.140.0030.03716.44
5.4.130.0070.03316.46
5.4.120.0130.03016.34
5.4.110.0030.03716.44
5.4.100.0070.03716.54
5.4.90.0030.04316.49
5.4.80.0070.03016.43
5.4.70.0100.05716.42
5.4.60.0000.04316.32
5.4.50.0030.03716.48
5.4.40.0070.03316.50
5.4.30.0100.05016.36
5.4.20.0030.03016.37
5.4.10.0100.03016.36
5.4.00.0030.03315.65
5.3.290.0030.06714.76
5.3.280.0030.05014.55
5.3.270.0000.04314.56
5.3.260.0000.04314.72
5.3.250.0100.05714.64
5.3.240.0030.03714.66
5.3.230.0070.04014.66
5.3.220.0000.04014.61
5.3.210.0100.03714.62
5.3.200.0000.04314.61
5.3.190.0070.04314.57
5.3.180.0070.03314.57
5.3.170.0070.03314.66
5.3.160.0030.04014.68
5.3.150.0070.03714.57
5.3.140.0130.06314.73
5.3.130.0030.03314.70
5.3.120.0030.07714.66
5.3.110.0070.03714.71
5.3.100.0030.04714.05
5.3.90.0100.07014.09
5.3.80.0130.07013.93
5.3.70.0100.06314.11
5.3.60.0100.07314.16
5.3.50.0130.06714.10
5.3.40.0100.07014.00
5.3.30.0100.05713.87
5.3.20.0000.05013.79
5.3.10.0030.06713.74
5.3.00.0100.07313.77
5.2.170.0070.04711.20
5.2.160.0130.02311.10
5.2.150.0070.04011.28
5.2.140.0100.06011.26
5.2.130.0070.05011.27
5.2.120.0030.06711.06
5.2.110.0070.06311.27
5.2.100.0030.06011.16
5.2.90.0070.06011.14
5.2.80.0030.06311.20
5.2.70.0070.06311.02
5.2.60.0070.05711.11
5.2.50.0030.06710.94
5.2.40.0030.06010.93
5.2.30.0070.06011.11
5.2.20.0000.06711.12
5.2.10.0130.05010.88
5.2.00.0070.05710.78
5.1.60.0030.0539.88
5.1.50.0200.04310.13
5.1.40.0070.04710.10
5.1.30.0030.05710.36
5.1.20.0030.04310.26
5.1.10.0000.06010.18
5.1.00.0070.05710.16
5.0.50.0030.0478.63
5.0.40.0000.0478.53
5.0.30.0000.0538.35
5.0.20.0030.0438.24
5.0.10.0030.0478.34
5.0.00.0000.0638.11
4.4.90.0000.0377.44
4.4.80.0030.0177.44
4.4.70.0030.0337.44
4.4.60.0030.0237.44
4.4.50.0070.0337.44
4.4.40.0030.0507.44
4.4.30.0000.0407.44
4.4.20.0030.0307.44
4.4.10.0000.0407.44
4.4.00.0130.0407.44
4.3.110.0070.0307.44
4.3.100.0030.0337.44
4.3.90.0000.0377.44
4.3.80.0000.0577.44
4.3.70.0000.0377.44
4.3.60.0100.0307.44
4.3.50.0030.0377.44
4.3.40.0000.0577.44
4.3.30.0070.0277.44
4.3.20.0000.0377.44
4.3.10.0000.0407.44
4.3.00.0030.0237.44

preferences:
38.01 ms | 401 KiB | 5 Q