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((string)$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): 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.70.0120.00618.35
8.3.60.0070.01016.88
8.3.50.0070.01217.42
8.3.40.0120.00318.94
8.3.30.0070.00718.57
8.3.20.0050.00318.85
8.3.10.0030.00620.52
8.3.00.0120.00417.50
8.2.180.0070.01416.88
8.2.170.0070.01422.96
8.2.160.0040.01120.37
8.2.150.0040.00424.18
8.2.140.0090.00624.66
8.2.130.0070.00026.16
8.2.120.0040.00422.09
8.2.110.0110.00020.94
8.2.100.0080.00417.84
8.2.90.0000.00819.22
8.2.80.0040.00417.97
8.2.70.0050.00317.75
8.2.60.0030.00517.93
8.2.50.0000.00818.07
8.2.40.0050.00318.16
8.2.30.0000.00718.20
8.2.20.0030.00617.73
8.2.10.0030.00519.44
8.2.00.0040.00417.73
8.1.280.0060.00925.92
8.1.270.0050.00223.99
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0000.00920.80
8.1.230.0090.00320.61
8.1.220.0030.00618.77
8.1.210.0040.00418.93
8.1.200.0030.00617.36
8.1.190.0000.00717.52
8.1.180.0040.00418.10
8.1.170.0050.00318.97
8.1.160.0040.00418.85
8.1.150.0040.00418.61
8.1.140.0040.00417.50
8.1.130.0070.00017.89
8.1.120.0040.00417.51
8.1.110.0030.00517.40
8.1.100.0040.00417.40
8.1.90.0000.00717.51
8.1.80.0070.00017.43
8.1.70.0000.00717.54
8.1.60.0040.00417.54
8.1.50.0040.00417.47
8.1.40.0060.00317.61
8.1.30.0000.00817.62
8.1.20.0040.00417.64
8.1.10.0000.00917.53
8.1.00.0000.00817.57
8.0.300.0040.00420.13
8.0.290.0030.00516.63
8.0.280.0070.00018.47
8.0.270.0000.00817.30
8.0.260.0030.00316.94
8.0.250.0000.00717.01
8.0.240.0050.00617.10
8.0.230.0060.00317.11
8.0.220.0070.00016.96
8.0.210.0000.00716.98
8.0.200.0000.00617.06
8.0.190.0040.00417.10
8.0.180.0080.00017.04
8.0.170.0050.00317.06
8.0.160.0070.00017.10
8.0.150.0050.00516.95
8.0.140.0070.00316.92
8.0.130.0060.00013.45
8.0.120.0030.00516.99
8.0.110.0070.00017.07
8.0.100.0040.00416.87
8.0.90.0000.00816.97
8.0.80.0060.01316.97
8.0.70.0030.00516.83
8.0.60.0040.00416.89
8.0.50.0070.00016.96
8.0.30.0110.01017.15
8.0.20.0110.00817.15
8.0.10.0000.00816.95
8.0.00.0090.00916.93
7.4.330.0000.00513.06
7.4.320.0030.00316.59
7.4.300.0000.00716.64
7.4.290.0070.00016.57
7.4.280.0000.01016.57
7.4.270.0030.00316.55
7.4.260.0030.00313.33
7.4.250.0080.00016.54
7.4.240.0070.00016.56
7.4.230.0030.00316.68
7.4.220.0090.00616.41
7.4.210.0080.00616.62
7.4.200.0070.00016.40
7.4.190.0070.00016.52
7.4.160.0040.01516.67
7.4.150.0120.01216.43
7.4.140.0090.00916.62
7.4.130.0060.01116.68
7.4.120.0100.00816.66
7.4.110.0060.01116.52
7.4.100.0090.00916.43
7.4.90.0070.01416.48
7.4.80.0090.00916.57
7.4.70.0130.00616.46
7.4.60.0100.00716.41
7.4.50.0000.00716.40
7.4.40.0000.01316.48
7.4.30.0060.01616.46
7.4.00.0080.01014.80
7.3.330.0030.00313.27
7.3.320.0000.00613.31
7.3.310.0070.00016.24
7.3.300.0070.00016.26
7.3.290.0100.00416.36
7.3.280.0040.01216.36
7.3.270.0070.01716.32
7.3.260.0160.00416.60
7.3.250.0150.00716.46
7.3.240.0110.00816.32
7.3.230.0060.00916.56
7.3.210.0160.00616.43
7.3.200.0030.01719.39
7.3.190.0080.01216.38
7.3.180.0140.00316.59
7.3.170.0060.01116.43
7.3.160.0100.00616.66
7.3.120.0100.00714.81
7.3.110.0060.01114.95
7.3.100.0060.00614.71
7.3.90.0070.00714.54
7.3.80.0000.01514.57
7.3.70.0040.00814.59
7.3.60.0000.01314.47
7.3.50.0000.01314.72
7.3.40.0060.00914.91
7.3.30.0090.00614.77
7.3.20.0030.00616.54
7.3.10.0030.01316.55
7.3.00.0090.00616.59
7.2.330.0090.00916.56
7.2.320.0180.00316.69
7.2.310.0060.01816.59
7.2.300.0100.00716.69
7.2.290.0120.00616.73
7.2.250.0080.01114.66
7.2.240.0060.01314.97
7.2.230.0060.01215.07
7.2.220.0030.01014.81
7.2.210.0000.01214.95
7.2.200.0000.01315.04
7.2.190.0110.00414.73
7.2.180.0150.00015.13
7.2.170.0040.01115.01
7.1.330.0070.00715.74
7.1.320.0050.00515.83
7.1.310.0070.00715.80
7.1.300.0040.00715.51
7.1.290.0100.00015.54
7.1.280.0090.00015.62
7.1.270.0030.00915.72
7.1.260.0000.01215.57
7.1.70.0000.00716.95
7.1.60.0030.01719.40
7.1.50.0060.01616.89
7.1.00.0070.07022.27
7.0.200.0000.00716.77
7.0.140.0100.07022.13
7.0.110.0500.06719.95
7.0.100.0330.04020.00
7.0.90.0400.06319.97
7.0.80.0270.03320.00
7.0.70.0470.02719.93
7.0.60.0570.06719.98
7.0.50.0500.06719.90
7.0.40.0070.03319.70
7.0.30.0100.07319.75
7.0.20.0100.03019.77
7.0.10.0000.03719.73
7.0.00.0100.06719.82
5.6.260.0000.05020.72
5.6.250.0030.04020.76
5.6.240.0030.08320.69
5.6.230.0130.07720.58
5.6.220.0100.07020.70
5.6.210.0030.05320.75
5.6.200.0000.04020.61
5.6.190.0170.07020.61
5.6.180.0030.06020.69
5.6.170.0030.04020.59
5.6.160.0000.05020.61
5.6.150.0030.04020.61
5.6.140.0030.07720.57
5.6.130.0070.06020.57
5.6.120.0030.07020.63
5.6.110.0030.07320.53
5.6.100.0100.06720.63
5.6.90.0030.04720.82
5.6.80.0100.06320.05
5.6.70.0030.03720.07
5.6.60.0000.03720.24
5.6.50.0030.03720.01
5.6.40.0130.06719.99
5.6.30.0000.04019.92
5.6.20.0030.04019.93
5.6.10.0000.04020.01
5.6.00.0030.03019.98
5.5.380.0030.03317.56
5.5.370.0070.06017.56
5.5.360.0070.03717.70
5.5.350.0000.04717.27
5.5.340.0030.03717.93
5.5.330.0000.03718.13
5.5.320.0100.03018.24
5.5.310.0000.03717.89
5.5.300.0100.04718.12
5.5.290.0000.04718.12
5.5.280.0030.04018.05
5.5.270.0030.08317.95
5.5.260.0070.07317.93
5.5.250.0070.03018.04
5.5.240.0070.04317.64
5.5.230.0070.08717.48
5.5.220.0100.06717.60
5.5.210.0000.05717.48
5.5.200.0000.04717.58
5.5.190.0000.03317.59
5.5.180.0000.04317.29
5.5.160.0000.03717.27
5.5.150.0070.06317.47
5.5.140.0030.03717.57
5.5.130.0000.03317.26
5.5.120.0000.06717.18
5.5.110.0030.03317.26
5.5.100.0000.08017.39
5.5.90.0030.03017.32
5.5.80.0070.05717.48
5.5.70.0000.03717.16
5.5.60.0030.07317.16
5.5.50.0030.07017.14
5.5.40.0030.03717.17
5.5.30.0000.03717.17
5.5.20.0030.03317.50
5.5.10.0000.07317.33
5.5.00.0000.06017.31
5.4.450.0000.06719.64
5.4.440.0100.07719.34
5.4.430.0070.03019.34
5.4.420.0070.05719.27
5.4.410.0030.04319.38
5.4.400.0100.05019.19
5.4.390.0000.06719.18
5.4.380.0170.05319.34
5.4.370.0000.07319.03
5.4.360.0000.05718.98
5.4.350.0000.07719.23
5.4.340.0000.04319.35
5.4.320.0000.05319.04
5.4.310.0100.02319.14
5.4.300.0070.07018.95
5.4.290.0000.08019.30
5.4.280.0000.08019.17
5.4.270.0070.06019.02
5.4.260.0000.06718.98
5.4.250.0030.07319.33
5.4.240.0000.03319.01
5.4.230.0030.07319.15
5.4.220.0000.07018.98
5.4.210.0000.08019.22
5.4.200.0070.06719.30
5.4.190.0070.06019.00
5.4.180.0000.06719.17
5.4.170.0000.06719.17
5.4.160.0000.08318.98
5.4.150.0000.05019.01
5.4.140.0030.06316.61
5.4.130.0030.07016.58
5.4.120.0030.06316.37
5.4.110.0070.05016.36
5.4.100.0030.04316.46
5.4.90.0000.05316.62
5.4.80.0000.05316.52
5.4.70.0030.03316.63
5.4.60.0070.07016.50
5.4.50.0000.04016.48
5.4.40.0030.05016.68
5.4.30.0030.04716.39
5.4.20.0070.03016.50
5.4.10.0070.03716.28
5.4.00.0000.04015.95
5.3.290.0030.03014.71
5.3.280.0000.03314.62
5.3.270.0030.03314.79
5.3.260.0000.07314.72
5.3.250.0030.07014.71
5.3.240.0030.07714.65
5.3.230.0030.06714.70
5.3.220.0000.03314.68
5.3.210.0100.08714.56
5.3.200.0070.07314.73
5.3.190.0000.04014.61
5.3.180.0000.04014.72
5.3.170.0000.06314.67
5.3.160.0030.04014.72
5.3.150.0000.04014.57
5.3.140.0000.05714.56
5.3.130.0000.03714.61
5.3.120.0100.02714.57
5.3.110.0070.03314.71
5.3.100.0000.04714.09
5.3.90.0030.03014.18
5.3.80.0070.03014.07
5.3.70.0000.05014.05
5.3.60.0000.03014.25
5.3.50.0000.03313.97
5.3.40.0000.05713.83
5.3.30.0000.03714.16
5.3.20.0030.07013.86
5.3.10.0000.08313.81
5.3.00.0030.06313.64

preferences:
41.56 ms | 401 KiB | 5 Q