3v4l.org

run code in 200+ 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)
7.4.00.0080.01014.80
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.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