3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)
7.3.0rc40.0160.00598.97
7.3.0rc30.0220.00416.43
7.3.0beta10.0060.00312.89
7.3.0alpha10.0190.00012.58
7.2.60.0160.00616.73
7.2.00.0070.00719.45
7.1.200.0030.00715.51
7.1.100.0060.00618.07
7.1.70.0040.00416.77
7.1.60.0060.01019.70
7.1.50.0250.00334.76
7.1.00.0000.07722.33
7.0.200.0000.00716.88
7.0.140.0130.06322.01
7.0.110.0000.05019.99
7.0.100.0100.07019.92
7.0.90.0070.08020.07
7.0.80.0030.07720.10
7.0.70.0000.04719.88
7.0.60.0070.05320.04
7.0.50.0100.07320.47
7.0.40.0030.04020.26
7.0.30.0070.03720.27
7.0.20.0030.04320.12
7.0.10.0030.04020.11
7.0.00.0070.05020.20
5.6.280.0100.06720.84
5.6.260.0070.04020.68
5.6.250.0100.04320.62
5.6.240.0030.04720.58
5.6.230.0030.04320.64
5.6.220.0100.08020.58
5.6.210.0030.06320.67
5.6.200.0170.03321.03
5.6.190.0030.04321.15
5.6.180.0130.06021.21
5.6.170.0100.03721.16
5.6.160.0100.07021.26
5.6.150.0000.04321.14
5.6.140.0000.04721.21
5.6.130.0070.04321.11
5.6.120.0100.03721.13
5.6.110.0030.06021.10
5.6.100.0130.07321.03
5.6.90.0000.04721.14
5.6.80.0070.04020.36
5.6.70.0100.03320.68
5.6.60.0130.06720.52
5.6.50.0070.07020.33
5.6.40.0070.08020.33
5.6.30.0070.06720.57
5.6.20.0100.08020.63
5.6.10.0100.07720.59
5.6.00.0100.07720.44
5.5.380.0030.08320.53
5.5.370.0100.07020.39
5.5.360.0100.07320.55
5.5.350.0030.07720.43
5.5.340.0030.04321.00
5.5.330.0030.04720.96
5.5.320.0130.03320.84
5.5.310.0100.07720.83
5.5.300.0070.04020.97
5.5.290.0000.04720.79
5.5.280.0030.04320.91
5.5.270.0070.06020.88
5.5.260.0000.04720.90
5.5.250.0070.03720.64
5.5.240.0070.03720.14
5.5.230.0130.06020.30
5.5.220.0030.07720.09
5.5.210.0070.08320.10
5.5.200.0130.07320.24
5.5.190.0030.08020.04
5.5.180.0200.06720.07
5.5.160.0170.04020.18
5.5.150.0070.06020.35
5.5.140.0070.06720.14
5.5.130.0070.07320.31
5.5.120.0170.07720.14
5.5.110.0100.07720.27
5.5.100.0030.08320.13
5.5.90.0100.07320.15
5.5.80.0000.06720.29
5.5.70.0070.08020.26
5.5.60.0130.07320.27
5.5.50.0130.07319.93
5.5.40.0130.07320.14
5.5.30.0200.06320.11
5.5.20.0100.07320.17
5.5.10.0130.07320.05
5.5.00.0130.07320.17
5.4.450.0030.03719.47
5.4.440.0000.04319.28
5.4.430.0030.04019.41
5.4.420.0000.04719.27
5.4.410.0000.04019.36
5.4.400.0070.05718.99
5.4.390.0070.06718.98
5.4.380.0000.06718.99
5.4.370.0030.08318.98
5.4.360.0070.08019.11
5.4.350.0100.07019.24
5.4.340.0170.06019.14
5.4.320.0100.07318.98
5.4.310.0100.05719.23
5.4.300.0000.05319.32
5.4.290.0030.07319.01
5.4.280.0070.08319.01
5.4.270.0000.08019.27
5.4.260.0000.08319.02
5.4.250.0070.04718.98
5.4.240.0100.07019.02
5.4.230.0030.07019.00
5.4.220.0130.07318.95
5.4.210.0070.05019.24
5.4.200.0100.07319.30
5.4.190.0070.07319.32
5.4.180.0030.05019.02
5.4.170.0070.08019.03
5.4.160.0000.05319.16
5.4.150.0070.08318.95
5.4.140.0030.07316.65
5.4.130.0100.06716.52
5.4.120.0130.06316.52
5.4.110.0030.07716.52
5.4.100.0130.07016.63
5.4.90.0070.07016.52
5.4.80.0100.05716.60
5.4.70.0070.07716.52
5.4.60.0030.04316.42
5.4.50.0030.06316.52
5.4.40.0170.06016.68
5.4.30.0100.06716.45
5.4.20.0030.06316.29
5.4.10.0030.05316.52
5.4.00.0070.07315.81
5.3.290.0030.08014.67
5.3.280.0100.07714.77
5.3.270.0030.07714.76
5.3.260.0030.07714.74
5.3.250.0030.08314.65
5.3.240.0100.07014.61
5.3.230.0170.04314.48
5.3.220.0100.07314.82
5.3.210.0100.04314.62
5.3.200.0070.06714.59
5.3.190.0070.04714.55
5.3.180.0070.05714.59
5.3.170.0130.07014.45
5.3.160.0200.05314.82
5.3.150.0000.05014.82
5.3.140.0030.05014.61
5.3.130.0030.08014.72
5.3.120.0000.08014.61
5.3.110.0000.07714.66
5.3.100.0070.07314.09
5.3.90.0030.05014.03
5.3.80.0100.06714.05
5.3.70.0130.07014.18
5.3.60.0030.07714.04
5.3.50.0130.07013.98
5.3.40.0200.06713.98
5.3.30.0130.07014.00
5.3.20.0070.07713.73
5.3.10.0130.06313.70
5.3.00.0070.04013.66
5.2.170.0030.06712.43
5.2.160.0100.05712.43
5.2.150.0070.06312.43
5.2.140.0030.06312.43
5.2.130.0000.06712.43
5.2.120.0130.05012.43
5.2.110.0070.06012.43
5.2.100.0100.06012.43
5.2.90.0100.06012.43
5.2.80.0000.07012.43
5.2.70.0070.06012.43
5.2.60.0100.03312.43
5.2.50.0030.06012.43
5.2.40.0070.04712.43
5.2.30.0130.05312.43
5.2.20.0170.05012.43
5.2.10.0070.05312.43
5.2.00.0030.05012.43
5.1.60.0100.04712.43
5.1.50.0030.05312.43
5.1.40.0030.05712.43
5.1.30.0070.05012.43
5.1.20.0030.03312.43
5.1.10.0030.05012.43
5.1.00.0000.03012.43
5.0.50.0030.04712.43
5.0.40.0030.04312.43
5.0.30.0000.07012.43
5.0.20.0070.04312.43
5.0.10.0070.03312.43
5.0.00.0070.06312.43
4.4.90.0030.02712.43
4.4.80.0070.03312.43
4.4.70.0070.02712.43
4.4.60.0030.02712.43
4.4.50.0030.03712.43
4.4.40.0030.05312.43
4.4.30.0000.03712.43
4.4.20.0000.03712.43
4.4.10.0030.03712.43
4.4.00.0000.05312.43
4.3.110.0030.03012.43
4.3.100.0030.03012.43
4.3.90.0000.03712.43
4.3.80.0030.05012.43
4.3.70.0000.03712.43
4.3.60.0070.03012.43
4.3.50.0070.03312.43
4.3.40.0030.03712.43
4.3.30.0000.03712.43
4.3.20.0030.02712.43
4.3.10.0000.03712.43
4.3.00.0030.03312.43