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($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 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[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], "\r\n\"'/"); } } } $var = array( array( 'text', 1, 1.1, true, false, null, array(), new stdClass, @fopen('php://stdin', 'r'), ), 'あ' => "\\/\"'&#\r\n\s\t\a\v\e\z", 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.60.0130.00318.30
8.3.50.0100.00621.99
8.3.40.0040.01818.97
8.3.30.0090.00619.12
8.3.20.0060.01320.29
8.3.10.0030.00623.65
8.3.00.0060.00319.38
8.2.180.0140.01018.29
8.2.170.0090.00622.96
8.2.160.0030.01720.53
8.2.150.0090.00924.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0080.00022.08
8.2.110.0040.00722.06
8.2.100.0110.00017.97
8.2.90.0030.00519.30
8.2.80.0060.00317.97
8.2.70.0120.00517.50
8.2.60.0070.00318.04
8.2.50.0000.00818.07
8.2.40.0040.00418.28
8.2.30.0030.00618.13
8.2.20.0000.01117.75
8.2.10.0050.00318.16
8.2.00.0080.00017.87
8.1.280.0070.01125.92
8.1.270.0070.00323.96
8.1.260.0000.00826.35
8.1.250.0070.01128.09
8.1.240.0030.00624.02
8.1.230.0000.01119.16
8.1.220.0000.00917.91
8.1.210.0000.00918.77
8.1.200.0030.00717.60
8.1.190.0000.00817.63
8.1.180.0040.00418.10
8.1.170.0030.00618.65
8.1.160.0040.00422.00
8.1.150.0030.00518.71
8.1.140.0000.00817.40
8.1.130.0000.00717.81
8.1.120.0020.00517.45
8.1.110.0040.00417.54
8.1.100.0000.00717.53
8.1.90.0040.00417.55
8.1.80.0050.00217.55
8.1.70.0070.00017.50
8.1.60.0030.00617.54
8.1.50.0000.00817.61
8.1.40.0040.00417.48
8.1.30.0080.00017.58
8.1.20.0030.00517.71
8.1.10.0080.00017.64
8.1.00.0040.00417.59
8.0.300.0040.00418.77
8.0.290.0040.00417.43
8.0.280.0040.00418.59
8.0.270.0000.00717.25
8.0.260.0040.00417.04
8.0.250.0050.00217.19
8.0.240.0000.00717.17
8.0.230.0040.00417.14
8.0.220.0030.00317.06
8.0.210.0030.00516.97
8.0.200.0000.00717.18
8.0.190.0030.00517.16
8.0.180.0000.00817.08
8.0.170.0030.00517.16
8.0.160.0040.00417.05
8.0.150.0050.00317.07
8.0.140.0000.00717.02
8.0.130.0030.00313.53
8.0.120.0070.00017.09
8.0.110.0050.00317.03
8.0.100.0000.00716.95
8.0.90.0000.00816.93
8.0.80.0060.01017.16
8.0.70.0050.00317.05
8.0.60.0040.00416.98
8.0.50.0000.00816.96
8.0.30.0100.00917.36
8.0.20.0100.01217.40
8.0.10.0080.00017.13
8.0.00.0080.01416.88
7.4.330.0050.00015.00
7.4.320.0000.00616.48
7.4.300.0030.00316.60
7.4.290.0030.00316.64
7.4.280.0050.00316.63
7.4.270.0070.00016.65
7.4.260.0030.00516.46
7.4.250.0000.00816.65
7.4.240.0020.00516.53
7.4.230.0020.00516.61
7.4.220.0090.01016.55
7.4.210.0110.00416.73
7.4.200.0000.00716.59
7.4.190.0080.00016.61
7.4.160.0120.00316.69
7.4.150.0100.01017.40
7.4.140.0110.00517.86
7.4.130.0090.00716.55
7.4.120.0100.00816.64
7.4.110.0130.00316.63
7.4.100.0110.00716.50
7.4.90.0120.00916.72
7.4.80.0140.00319.39
7.4.70.0130.00316.43
7.4.60.0070.01316.52
7.4.50.0040.00416.45
7.4.40.0070.01022.77
7.4.30.0100.00616.46
7.4.00.0060.01015.02
7.3.330.0030.00313.30
7.3.320.0000.00613.20
7.3.310.0000.00716.54
7.3.300.0000.00716.39
7.3.290.0000.01416.37
7.3.280.0110.00816.46
7.3.270.0120.00917.40
7.3.260.0040.01516.30
7.3.250.0050.01216.49
7.3.240.0180.00616.46
7.3.230.0130.00416.39
7.3.210.0060.01116.48
7.3.200.0190.00319.39
7.3.190.0060.01316.57
7.3.180.0070.01016.51
7.3.170.0090.00616.30
7.3.160.0180.00616.30
7.3.120.0110.00314.91
7.3.10.0040.01116.27
7.3.00.0070.00716.69
7.2.330.0030.01416.52
7.2.320.0140.00316.77
7.2.310.0090.00916.59
7.2.300.0120.00616.49
7.2.290.0060.01616.57
7.2.130.0030.01016.78
7.2.120.0110.00716.63
7.2.110.0040.01916.82
7.2.100.0070.01016.70
7.2.90.0070.01316.86
7.2.80.0150.00316.97
7.2.70.0130.00616.80
7.2.60.0050.01116.97
7.2.50.0070.00316.90
7.2.40.0070.00716.44
7.2.30.0060.00616.55
7.2.20.0080.00816.94
7.2.10.0090.00916.85
7.2.00.0040.01516.82
7.1.250.0150.00615.91
7.1.240.0060.00615.70
7.1.230.0160.00315.75
7.1.220.0070.01115.70
7.1.210.0060.00915.62
7.1.200.0050.00915.67
7.1.190.0030.00615.59
7.1.180.0090.00915.79
7.1.170.0060.00615.75
7.1.160.0070.01115.58
7.1.150.0030.01015.51
7.1.140.0060.01215.63
7.1.130.0210.00315.75
7.1.120.0140.00715.60
7.1.110.0140.00715.95
7.1.100.0080.00415.76
7.1.90.0220.00315.75
7.1.80.0030.01015.66
7.1.70.0080.00616.44
7.1.60.0090.01017.60
7.1.50.0050.01416.34
7.1.40.0110.01115.71
7.1.30.0060.01015.58
7.1.20.0150.00315.64
7.1.10.0040.00715.67
7.1.00.0060.03818.97
7.0.330.0030.01015.28
7.0.320.0040.01115.18
7.0.310.0130.00015.37
7.0.300.0080.01115.30
7.0.290.0100.00315.43
7.0.280.0070.00715.39
7.0.270.0080.01114.96
7.0.260.0160.00315.29
7.0.250.0190.00015.41
7.0.240.0100.01015.39
7.0.230.0120.00615.13
7.0.220.0080.00815.26
7.0.210.0070.00715.27
7.0.200.0110.00116.03
7.0.190.0110.01115.10
7.0.180.0060.00315.37
7.0.170.0150.00415.25
7.0.160.0120.00315.48
7.0.150.0030.01315.25
7.0.140.0040.04218.70
7.0.130.0040.00715.40
7.0.120.0060.00615.56
7.0.110.0040.00415.23
7.0.100.0120.00315.50
7.0.90.0340.04117.63
7.0.80.0290.02917.63
7.0.70.0370.04217.60
7.0.60.0250.02317.72
7.0.50.0240.02417.79
7.0.40.0110.01816.63
7.0.30.0050.04116.65
7.0.20.0080.03516.67
7.0.10.0080.02316.78
7.0.00.0030.03016.66
5.6.380.0040.00714.39
5.6.370.0030.01414.15
5.6.360.0100.00714.19
5.6.350.0110.00314.18
5.6.340.0070.00714.34
5.6.330.0030.01014.09
5.6.320.0070.00714.40
5.6.310.0030.00714.22
5.6.300.0040.00414.61
5.6.290.0060.00614.57
5.6.280.0050.04017.87
5.6.270.0040.01114.39
5.6.260.0000.01214.29
5.6.250.0000.01614.21
5.6.240.0090.04517.49
5.6.230.0080.02517.46
5.6.220.0080.02017.43
5.6.210.0070.02317.50
5.6.200.0050.02317.60
5.6.190.0070.03317.64
5.6.180.0100.01917.70
5.6.170.0080.02417.65
5.6.160.0020.03217.57
5.6.150.0060.04217.72
5.6.140.0050.02817.59
5.6.130.0050.02717.55
5.6.120.0050.02817.66
5.6.110.0050.02217.46
5.6.100.0020.02717.54
5.6.90.0120.04717.52
5.6.80.0110.01717.31
5.6.70.0100.02017.27
5.6.60.0050.03417.27
5.6.50.0070.02717.31
5.6.40.0090.04417.24
5.6.30.0090.04517.28
5.6.20.0100.04017.21
5.6.10.0100.04117.32
5.6.00.0050.05017.33
5.5.380.0090.03715.94
5.5.370.0060.03215.84
5.5.360.0150.01815.70
5.5.350.0060.03815.61
5.5.340.0020.02715.95
5.5.330.0050.02315.91
5.5.320.0080.02115.99
5.5.310.0040.02416.05
5.5.300.0030.02616.08
5.5.290.0050.02416.08
5.5.280.0020.02715.66
5.5.270.0050.02315.71
5.5.260.0070.02315.72
5.5.250.0100.02715.87
5.5.240.0030.02315.68
5.5.230.0070.04715.57
5.5.220.0030.02815.65
5.5.210.0090.02215.76
5.5.200.0070.04315.63
5.5.190.0080.04415.71
5.5.180.0110.03515.69
5.5.170.0130.00311.21
5.5.160.0060.03615.67
5.5.150.0090.03015.62
5.5.140.0070.02515.66
5.5.130.0010.03815.65
5.5.120.0040.02915.73
5.5.110.0070.04015.72
5.5.100.0050.04415.52
5.5.90.0060.03615.46
5.5.80.0040.02515.55
5.5.70.0030.02815.65
5.5.60.0050.04115.60
5.5.50.0080.02415.61
5.5.40.0080.04015.50
5.5.30.0080.03515.68
5.5.20.0050.04115.69
5.5.10.0080.03515.56
5.5.00.0100.04015.57
5.4.450.0020.02415.37
5.4.440.0040.02215.23
5.4.430.0050.02515.30
5.4.420.0040.02215.20
5.4.410.0030.02115.06
5.4.400.0130.01315.10
5.4.390.0100.03614.99
5.4.380.0050.02314.97
5.4.370.0030.02215.10
5.4.360.0080.01815.04
5.4.350.0030.02715.03
5.4.340.0060.02314.93
5.4.330.0030.01011.02
5.4.320.0080.03615.01
5.4.310.0030.02714.99
5.4.300.0080.02315.02
5.4.290.0100.02015.05
5.4.280.0020.03415.14
5.4.270.0080.02514.82
5.4.260.0050.04114.92
5.4.250.0080.02214.75
5.4.240.0030.04314.90
5.4.230.0020.04414.82
5.4.220.0030.03514.99
5.4.210.0050.02014.94
5.4.200.0050.03814.91
5.4.190.0050.02715.01
5.4.180.0070.04215.09
5.4.170.0070.04415.03
5.4.160.0080.03314.88
5.4.150.0070.03514.98
5.4.140.0080.03313.63
5.4.130.0070.03713.56
5.4.120.0010.03613.76
5.4.110.0100.03313.55
5.4.100.0110.03613.68
5.4.90.0060.03313.79
5.4.80.0070.03913.65
5.4.70.0090.03313.66
5.4.60.0050.03513.65
5.4.50.0070.03413.65
5.4.40.0070.03913.70
5.4.30.0020.04213.79
5.4.20.0060.02413.73
5.4.10.0060.03513.65
5.4.00.0040.03713.37
5.3.290.0030.04312.75
5.3.280.0100.03312.53
5.3.270.0060.04012.70
5.3.260.0050.04012.67
5.3.250.0060.04112.57
5.3.240.0050.04312.69
5.3.230.0030.04212.61
5.3.220.0050.04312.49
5.3.210.0060.03612.55
5.3.200.0020.02312.49
5.3.190.0050.03712.63
5.3.180.0100.03712.69
5.3.170.0050.04012.57
5.3.160.0070.03512.67
5.3.150.0050.03312.62
5.3.140.0070.03812.66
5.3.130.0080.03312.60
5.3.120.0030.04012.48
5.3.110.0050.04212.59
5.3.100.0070.02912.38
5.3.90.0040.04112.36
5.3.80.0070.02712.27
5.3.70.0030.04212.30
5.3.60.0020.04212.24
5.3.50.0020.03112.35
5.3.40.0060.03612.31
5.3.30.0020.03212.38
5.3.20.0050.03712.20
5.3.10.0050.04012.06
5.3.00.0030.02612.01
5.2.170.0030.03310.79
5.2.160.0030.03610.65
5.2.150.0030.03210.75
5.2.140.0030.02610.72
5.2.130.0030.03310.62
5.2.120.0080.02610.70
5.2.110.0100.02210.69
5.2.100.0070.01310.66
5.2.90.0030.03110.75
5.2.80.0040.03110.64
5.2.70.0050.02810.72
5.2.60.0030.03210.63
5.2.50.0040.03710.68
5.2.40.0090.03010.57
5.2.30.0050.03310.62
5.2.20.0030.03710.65
5.2.10.0040.02710.59
5.2.00.0070.03010.56
5.1.60.0020.03110.14
5.1.50.0060.01610.09
5.1.40.0070.02510.20
5.1.30.0050.02910.35
5.1.20.0060.02710.30
5.1.10.0020.03110.10
5.1.00.0000.02510.18
5.0.50.0060.0179.35
5.0.40.0030.0199.28
5.0.30.0050.0279.32
5.0.20.0030.0249.25
5.0.10.0020.0259.20
5.0.00.0020.0329.28
4.4.90.0060.0179.20
4.4.80.0070.0179.20
4.4.70.0070.0179.20
4.4.60.0030.0189.20
4.4.50.0030.0219.20
4.4.40.0010.0319.20
4.4.30.0030.0219.20
4.4.20.0030.0169.20
4.4.10.0000.0249.20
4.4.00.0050.0279.20
4.3.110.0000.0209.20
4.3.100.0020.0189.20
4.3.90.0020.0229.20
4.3.80.0020.0299.20
4.3.70.0000.0189.20
4.3.60.0020.0209.20
4.3.50.0030.0209.20
4.3.40.0050.0259.20
4.3.30.0020.0179.20
4.3.20.0020.0209.20
4.3.10.0030.0199.20
4.3.00.0020.0209.20

preferences:
42.63 ms | 401 KiB | 5 Q