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 = '"'. addcslashes($k, '"\\') . '"'; $data[] = $k . ':' . $v; } else { $data[] = $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) && _js_error(): return 'null'; case is_string($value): return '"' . _js_uc_esc($value) . '"'; default: return $value; } } function _js_error() { return trigger_error('json_encode(): type is unsupported, encoded as null', E_USER_WARNING); } 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( array( 'text', 1, 1.1, true, false, null, array(), new stdClass, @fopen('php://stdin', 'r'), ), 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.00316.58
8.3.60.0140.00318.21
8.3.50.0110.00921.92
8.3.40.0090.00618.92
8.3.30.0150.00618.83
8.3.20.0080.00018.60
8.3.10.0060.00321.27
8.3.00.0030.00523.33
8.2.180.0110.00418.54
8.2.170.0110.01122.96
8.2.160.0030.01220.57
8.2.150.0000.00824.18
8.2.140.0000.00824.66
8.2.130.0000.00726.16
8.2.120.0050.00221.13
8.2.110.0030.00620.44
8.2.100.0090.00317.84
8.2.90.0040.00419.17
8.2.80.0030.00517.97
8.2.70.0000.00917.63
8.2.60.0000.00817.93
8.2.50.0090.00318.07
8.2.40.0000.00818.00
8.2.30.0000.00819.56
8.2.20.0060.00317.67
8.2.10.0050.00317.80
8.2.00.0050.00517.73
8.1.280.0150.00025.92
8.1.270.0070.00323.99
8.1.260.0040.01226.35
8.1.250.0000.00828.09
8.1.240.0090.00022.45
8.1.230.0040.00721.01
8.1.220.0080.00018.77
8.1.210.0030.00519.04
8.1.200.0060.00317.35
8.1.190.0040.00417.53
8.1.180.0030.00518.10
8.1.170.0080.00018.69
8.1.160.0080.00018.84
8.1.150.0050.00318.67
8.1.140.0040.00417.53
8.1.130.0070.00017.95
8.1.120.0000.00817.43
8.1.110.0070.00317.57
8.1.100.0040.00417.52
8.1.90.0080.00017.54
8.1.80.0030.00517.61
8.1.70.0000.00817.41
8.1.60.0030.00717.55
8.1.50.0040.00417.53
8.1.40.0000.00717.48
8.1.30.0040.00417.59
8.1.20.0000.00917.66
8.1.10.0060.00317.54
8.1.00.0030.00817.46
8.0.300.0040.00420.15
8.0.290.0030.00517.30
8.0.280.0040.00418.68
8.0.270.0070.00017.39
8.0.260.0000.00717.07
8.0.250.0070.00017.03
8.0.240.0060.00317.18
8.0.230.0070.00017.20
8.0.220.0030.00317.00
8.0.210.0030.00617.12
8.0.200.0030.00317.13
8.0.190.0000.00817.13
8.0.180.0040.00417.12
8.0.170.0070.00017.02
8.0.160.0000.00717.02
8.0.150.0070.00017.04
8.0.140.0020.00516.98
8.0.130.0060.00013.47
8.0.120.0050.00216.93
8.0.110.0040.00417.20
8.0.100.0040.00417.12
8.0.90.0000.00716.96
8.0.80.0070.01317.06
8.0.70.0050.00216.96
8.0.60.0030.00516.97
8.0.50.0000.00817.14
8.0.30.0140.00517.24
8.0.20.0140.00617.43
8.0.10.0000.00816.97
8.0.00.0120.00716.82
7.4.330.0020.00216.88
7.4.320.0030.00316.63
7.4.300.0000.00616.67
7.4.290.0060.00316.56
7.4.280.0030.00316.61
7.4.270.0040.00716.68
7.4.260.0000.00613.27
7.4.250.0040.00416.56
7.4.240.0040.00416.65
7.4.230.0070.00016.75
7.4.220.0030.01616.42
7.4.210.0100.00716.63
7.4.200.0040.00416.67
7.4.190.0050.00216.55
7.4.160.0100.00616.63
7.4.150.0140.00317.40
7.4.140.0050.01417.86
7.4.130.0090.01016.66
7.4.120.0070.01016.54
7.4.110.0090.00916.71
7.4.100.0120.00516.49
7.4.90.0070.01116.47
7.4.80.0060.01219.39
7.4.70.0120.00616.62
7.4.60.0070.01016.51
7.4.50.0060.00316.48
7.4.40.0030.01022.77
7.4.30.0110.00716.66
7.4.00.0090.00615.21
7.3.330.0000.00513.29
7.3.320.0030.00313.25
7.3.310.0070.00016.43
7.3.300.0040.00416.42
7.3.290.0100.01316.34
7.3.280.0050.01016.47
7.3.270.0170.00017.40
7.3.260.0100.00818.24
7.3.250.0120.00516.44
7.3.240.0130.00316.65
7.3.230.0140.00316.46
7.3.210.0030.01316.30
7.3.200.0130.00619.39
7.3.190.0060.01016.62
7.3.180.0080.00816.36
7.3.170.0040.01116.54
7.3.160.0060.01016.36
7.3.120.0130.00314.88
7.2.330.0100.00716.53
7.2.320.0070.01116.62
7.2.310.0090.00716.77
7.2.300.0100.01416.50
7.2.290.0110.01416.54
7.2.60.0160.00016.71
7.2.00.0000.01019.51
7.1.200.0120.00315.68
7.1.70.0070.00217.40
7.1.60.0070.00717.40
7.1.50.0040.00717.40
7.1.40.0040.00817.40
7.1.30.0040.01317.40
7.1.20.0040.00917.40
7.1.10.0060.00317.40
7.1.00.0000.01017.40
7.0.200.0080.00017.40
7.0.190.0000.00917.40
7.0.180.0000.01017.40
7.0.170.0070.00417.40
7.0.160.0050.00517.40
7.0.150.0000.00717.40
7.0.140.0000.00717.40
7.0.130.0040.00817.40
7.0.120.0040.00417.40
7.0.110.0050.00317.40
7.0.100.0000.00917.40
7.0.90.0080.00017.40
7.0.80.0000.01117.40
7.0.70.0060.00617.40
7.0.60.0030.00617.40
7.0.50.0040.00417.40
7.0.40.0040.00817.40
7.0.30.0000.00817.40
7.0.20.0000.00817.40
7.0.10.0040.00417.40
7.0.00.0000.00817.40
5.6.300.0060.04121.02
5.6.290.0030.05920.81
5.6.280.0000.04421.02
5.6.270.0070.03620.87
5.6.260.0070.03721.01
5.6.250.0100.03821.01
5.6.240.0030.04920.85
5.6.230.0060.03920.89
5.6.220.0030.04620.86
5.6.210.0000.04620.60
5.6.200.0100.03820.87
5.6.190.0070.03920.85
5.6.180.0030.03920.85
5.6.170.0070.03720.75
5.6.160.0030.04220.94
5.6.150.0060.04820.84
5.6.140.0030.04120.81
5.6.130.0000.04621.06
5.6.120.0070.04920.99
5.6.110.0070.03820.96
5.6.100.0030.04421.02
5.6.90.0000.04320.82
5.6.80.0030.04220.21
5.6.70.0100.03520.43
5.6.60.0030.04120.21
5.6.50.0030.03920.34
5.6.40.0070.04020.16
5.6.30.0030.04220.21
5.6.20.0030.03820.21
5.6.10.0000.04420.40
5.6.00.0100.04220.27
5.5.380.0070.04917.41
5.5.370.0070.03617.64
5.5.360.0000.04517.62
5.5.350.0000.04417.58
5.5.340.0000.04218.10
5.5.330.0060.03818.00
5.5.320.0030.04218.09
5.5.310.0070.03717.75
5.5.300.0000.04618.09
5.5.290.0070.03718.09
5.5.280.0070.05818.04
5.5.270.0000.04417.70
5.5.260.0030.04318.09
5.5.250.0000.04417.90
5.5.240.0030.03817.48
5.5.230.0030.05117.56
5.5.220.0030.03817.55
5.5.210.0070.03717.47
5.5.200.0000.04317.40
5.5.190.0030.03817.40
5.5.180.0030.04117.40
5.5.160.0070.04017.40
5.5.150.0030.04217.40
5.5.140.0030.04217.43
5.5.130.0030.04217.48
5.5.120.0000.04117.44
5.5.110.0000.04117.47
5.5.100.0060.03617.40
5.5.90.0030.03617.40
5.5.80.0030.08017.40
5.5.70.0030.04117.40
5.5.60.0030.03717.40
5.5.50.0000.04417.42
5.5.40.0000.03917.40
5.5.30.0070.04117.40
5.5.20.0330.03317.40
5.5.10.0000.05017.40
5.5.00.0070.06817.40
5.4.450.0100.03619.58
5.4.440.0030.03919.49
5.4.430.0060.03819.38
5.4.420.0060.03519.21
5.4.410.0240.03419.43
5.4.400.0140.05118.98
5.4.390.0030.04219.04
5.4.380.0320.03619.11
5.4.370.0030.03919.00
5.4.360.0170.05119.09
5.4.350.0070.04019.20
5.4.340.0030.03818.98
5.4.320.0030.04319.13
5.4.310.0030.03919.20
5.4.300.0030.03518.98
5.4.290.0030.03619.25
5.4.280.0000.04219.07
5.4.270.0030.03919.14
5.4.260.0060.04219.23
5.4.250.0030.06219.07
5.4.240.0000.04818.92
5.4.230.0000.04018.98
5.4.220.0000.04419.20
5.4.210.0030.03918.98
5.4.200.0030.03818.92
5.4.190.0100.04819.22
5.4.180.0030.03619.05
5.4.170.0000.04018.96
5.4.160.0070.04219.04
5.4.150.0070.04318.96
5.4.140.0030.03717.40
5.4.130.0030.04317.40
5.4.120.0130.03517.40
5.4.110.0000.04017.40
5.4.100.0030.03317.40
5.4.90.0030.03417.40
5.4.80.0030.03617.40
5.4.70.0070.03117.40
5.4.60.0030.03417.40
5.4.50.0000.03817.40
5.4.40.0030.04317.40
5.4.30.0000.04217.40
5.4.20.0000.03817.40
5.4.10.0000.04117.40
5.4.00.0000.04017.40
5.3.290.0000.04317.40
5.3.280.0000.03917.40
5.3.270.0090.03517.40
5.3.260.0070.05017.40
5.3.250.0040.03917.40
5.3.240.0000.05817.40
5.3.230.0030.03817.40
5.3.220.0240.03017.40
5.3.210.0000.04017.40
5.3.200.0000.03917.40
5.3.190.0030.03617.40
5.3.180.0000.05317.40
5.3.170.0100.02917.40
5.3.160.0030.03617.40
5.3.150.0130.05117.40
5.3.140.0000.03917.40
5.3.130.0060.04817.40
5.3.120.0030.04317.40
5.3.110.0030.04117.40
5.3.100.0030.03817.40
5.3.90.0000.04217.40
5.3.80.0000.04017.40
5.3.70.0030.04217.40
5.3.60.0000.04217.40
5.3.50.0030.03417.40
5.3.40.0000.03717.40
5.3.30.0000.03917.40
5.3.20.0130.03317.40
5.3.10.0000.03617.40
5.3.00.0130.03017.40
5.2.170.0000.03617.40
5.2.160.0160.02917.40
5.2.150.0040.03217.40
5.2.140.0030.03017.40
5.2.130.0030.03617.40
5.2.120.0000.03017.40
5.2.110.0000.03217.40
5.2.100.0030.02717.40
5.2.90.0040.02817.40
5.2.80.0030.02717.40
5.2.70.0030.06317.40
5.2.60.0040.03217.40
5.2.50.0100.03217.40
5.2.40.0030.03017.40
5.2.30.0060.04217.40
5.2.20.0030.03317.40
5.2.10.0030.02817.40
5.2.00.0060.02617.40
5.1.60.0100.01917.40
5.1.50.0000.03117.40
5.1.40.0000.03517.40
5.1.30.0030.02417.40
5.1.20.0000.02817.40
5.1.10.0000.02917.40
5.1.00.0060.02117.40
5.0.50.0000.02217.40
5.0.40.0040.01917.40
5.0.30.0030.06617.40
5.0.20.0060.01617.40
5.0.10.0070.02017.40
5.0.00.0000.03117.40
4.4.90.0000.02317.40
4.4.80.0000.01817.40
4.4.70.0030.01417.40
4.4.60.0030.01617.40
4.4.50.0070.01817.40
4.4.40.0000.03117.40
4.4.30.0030.01517.40
4.4.20.0030.01517.40
4.4.10.0060.01217.40
4.4.00.0030.02417.40
4.3.110.0000.01917.40
4.3.100.0070.01017.40
4.3.90.0000.01617.40
4.3.80.0100.02617.40
4.3.70.0000.01717.40
4.3.60.0030.01317.40
4.3.50.0030.01317.40
4.3.40.0030.02317.40
4.3.30.0000.01717.40
4.3.20.0000.04217.40
4.3.10.0030.01917.40
4.3.00.0000.01817.40

preferences:
38.86 ms | 401 KiB | 5 Q