3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('json_encode')) { function json_encode($it) { $tmp = $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 $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-\x10\x0c\x0d\\\\\"/]|([^\x08-\x10\x0c\x0d\x32-\x7f\\\\\"/])++@"; 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\x10\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)); */ var_dump(json_encode(array('1'=>'hoge')));

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.0070.00716.50
8.3.50.0090.00722.09
8.3.40.0120.00618.64
8.3.30.0070.01418.79
8.3.20.0040.00420.29
8.3.10.0040.00423.71
8.3.00.0090.00020.95
8.2.180.0100.01018.16
8.2.170.0110.00422.96
8.2.160.0030.01020.52
8.2.150.0000.00924.18
8.2.140.0060.00324.66
8.2.130.0040.00426.16
8.2.120.0050.00322.26
8.2.110.0030.00622.16
8.2.100.0110.00017.78
8.2.90.0080.00019.21
8.2.80.0000.00817.97
8.2.70.0070.00417.50
8.2.60.0000.00817.80
8.2.50.0000.00818.07
8.2.40.0060.00318.03
8.2.30.0020.00518.05
8.2.20.0050.00317.68
8.2.10.0000.00717.75
8.2.00.0050.00317.62
8.1.280.0090.00925.92
8.1.270.0070.00023.96
8.1.260.0090.00026.35
8.1.250.0040.00428.09
8.1.240.0070.00323.95
8.1.230.0040.00719.13
8.1.220.0060.00317.74
8.1.210.0040.00418.77
8.1.200.0030.00617.36
8.1.190.0050.00317.53
8.1.180.0000.00918.10
8.1.170.0000.00818.78
8.1.160.0040.00421.96
8.1.150.0070.00018.56
8.1.140.0060.00317.44
8.1.130.0000.00717.84
8.1.120.0000.00717.36
8.1.110.0030.00517.42
8.1.100.0080.00017.37
8.1.90.0000.00817.44
8.1.80.0030.00317.48
8.1.70.0050.00217.43
8.1.60.0000.00817.43
8.1.50.0000.00817.46
8.1.40.0080.00017.52
8.1.30.0040.00417.66
8.1.20.0000.00817.72
8.1.10.0040.00417.41
8.1.00.0000.01117.38
8.0.300.0030.00718.77
8.0.290.0070.00017.16
8.0.280.0030.00318.52
8.0.270.0000.00717.14
8.0.260.0030.00316.86
8.0.250.0000.00616.94
8.0.240.0000.00816.87
8.0.230.0000.00717.01
8.0.220.0040.00416.97
8.0.210.0000.00716.94
8.0.200.0070.00017.00
8.0.190.0000.00716.83
8.0.180.0030.00716.81
8.0.170.0000.00816.82
8.0.160.0050.00316.86
8.0.150.0040.00416.87
8.0.140.0000.00816.91
8.0.130.0030.00313.38
8.0.120.0030.00516.84
8.0.110.0000.00716.86
8.0.100.0070.00016.77
8.0.90.0080.00016.88
8.0.80.0080.00816.95
8.0.70.0040.00416.80
8.0.60.0000.00716.76
8.0.50.0040.00416.84
8.0.30.0170.00517.16
8.0.20.0090.01017.40
8.0.10.0040.00416.86
8.0.00.0090.00916.63
7.4.330.0030.00315.02
7.4.320.0000.00716.60
7.4.300.0030.00316.52
7.4.290.0030.00316.48
7.4.280.0000.00716.62
7.4.270.0030.00316.50
7.4.260.0000.00916.59
7.4.250.0000.00716.43
7.4.240.0020.00516.41
7.4.230.0000.00716.58
7.4.220.0070.01116.56
7.4.210.0040.01216.46
7.4.200.0040.00416.54
7.4.190.0070.00016.40
7.4.160.0000.01616.44
7.4.150.0140.00317.40
7.4.140.0060.01117.86
7.4.130.0100.01016.45
7.4.120.0030.01416.40
7.4.110.0120.00416.52
7.4.100.0070.01116.52
7.4.90.0130.00316.28
7.4.80.0170.02619.39
7.4.70.0130.00316.52
7.4.60.0130.00316.63
7.4.50.0040.00416.57
7.4.40.0050.00722.77
7.4.30.0150.00616.57
7.4.10.0070.01016.38
7.4.00.0070.00915.48
7.3.330.0050.00013.17
7.3.320.0000.00513.27
7.3.310.0000.00616.27
7.3.300.0070.00016.20
7.3.290.0120.00916.26
7.3.280.0100.01016.21
7.3.270.0140.00317.40
7.3.260.0120.00616.25
7.3.250.0150.00416.19
7.3.240.0030.01916.18
7.3.230.0110.00816.39
7.3.210.0090.01316.32
7.3.200.0110.00719.39
7.3.190.0100.01316.55
7.3.180.0170.00016.26
7.3.170.0100.00716.30
7.3.160.0060.00916.50
7.3.130.0090.00916.51
7.3.120.0070.01015.34
7.3.110.0070.00915.34
7.3.100.0070.00715.07
7.3.90.0030.01115.24
7.3.80.0020.01315.09
7.3.70.0040.00715.07
7.3.60.0070.00515.20
7.3.50.0050.00915.16
7.3.40.0070.00815.29
7.3.30.0050.00815.25
7.3.20.0040.01117.11
7.3.10.0060.00816.83
7.3.00.0070.00716.78
7.2.330.0090.00916.58
7.2.320.0170.00016.64
7.2.310.0070.01016.30
7.2.300.0100.00616.54
7.2.290.0130.00316.41
7.2.260.0110.00716.38
7.2.250.0100.00815.72
7.2.240.0070.00915.43
7.2.230.0050.01015.34
7.2.220.0030.01015.29
7.2.210.0040.01015.29
7.2.200.0030.01215.29
7.2.190.0020.01015.49
7.2.180.0010.01215.33
7.2.170.0060.00815.46
7.2.160.0050.00815.59
7.2.150.0070.01017.32
7.2.140.0060.01017.38
7.2.130.0050.00917.30
7.2.120.0060.01017.18
7.2.110.0090.00617.29
7.2.100.0080.00817.18
7.2.90.0090.00717.35
7.2.80.0080.00717.24
7.2.70.0020.01117.18
7.2.60.0090.00417.26
7.2.50.0090.00717.14
7.2.40.0050.00917.13
7.2.30.0070.00817.28
7.2.20.0060.00717.19
7.2.10.0080.00817.27
7.2.00.0090.00917.61
7.1.330.0060.01116.14
7.1.320.0050.00916.20
7.1.310.0060.00616.01
7.1.300.0080.00416.09
7.1.290.0040.00916.05
7.1.280.0060.00816.17
7.1.270.0030.01016.16
7.1.260.0090.00416.12
7.1.250.0030.01016.26
7.1.240.0120.00417.29
7.1.230.0100.01017.01
7.1.220.0070.00717.08
7.1.210.0140.00317.18
7.1.200.0030.01017.20
7.1.190.0060.00917.06
7.1.180.0030.01317.18
7.1.170.0100.00717.00
7.1.160.0090.00917.13
7.1.150.0040.00817.22
7.1.140.0070.01017.12
7.1.130.0060.00817.23
7.1.120.0030.01017.12
7.1.110.0070.01017.09
7.1.100.0110.00317.49
7.1.90.0000.01017.30
7.1.80.0110.00417.15
7.1.70.0050.00517.12
7.1.60.0100.00818.14
7.1.50.0070.01216.81
7.1.40.0030.01717.07
7.1.30.0000.01017.18
7.1.20.0030.01017.04
7.1.10.0000.01317.32
7.1.00.0030.04519.82
7.0.330.0030.01016.72
7.0.320.0150.00316.74
7.0.310.0090.00617.04
7.0.300.0090.00317.10
7.0.290.0090.00316.79
7.0.280.0140.00416.93
7.0.270.0100.00316.92
7.0.260.0100.00316.87
7.0.250.0060.01016.92
7.0.240.0030.00917.06
7.0.230.0110.00616.91
7.0.220.0030.01017.00
7.0.210.0000.01616.68
7.0.200.0000.01116.87
7.0.190.0100.01016.99
7.0.180.0040.01116.96
7.0.170.0070.00416.86
7.0.160.0000.01117.01
7.0.150.0090.00316.80
7.0.140.0070.03819.43
7.0.130.0100.00716.89
7.0.120.0030.00916.85
7.0.110.0060.00316.93
7.0.100.0000.01216.72
7.0.90.0080.03818.39
7.0.80.0280.04518.42
7.0.70.0270.02718.40
7.0.60.0240.02318.41
7.0.50.0070.02318.60
7.0.40.0020.05317.48
7.0.30.0030.02517.44
7.0.20.0070.02517.54
7.0.10.0050.02117.45
7.0.00.0030.02717.37
5.6.400.0100.00715.67
5.6.390.0030.01015.89
5.6.380.0080.00415.84
5.6.370.0090.00615.96
5.6.360.0090.00916.12
5.6.350.0030.01016.13
5.6.340.0030.01015.91
5.6.330.0050.00515.89
5.6.320.0000.01415.96
5.6.310.0070.01015.88
5.6.300.0070.00715.79
5.6.290.0090.00615.88
5.6.280.0050.04218.44
5.6.270.0030.01415.52
5.6.260.0040.01116.20
5.6.250.0070.00716.09
5.6.240.0080.02118.24
5.6.230.0070.04818.43
5.6.220.0090.03918.06
5.6.210.0030.04218.03
5.6.200.0040.02818.33
5.6.190.0040.02618.34
5.6.180.0050.02618.32
5.6.170.0050.02718.46
5.6.160.0050.02718.46
5.6.150.0070.04218.46
5.6.140.0050.02518.46
5.6.130.0040.02718.35
5.6.120.0100.02618.42
5.6.110.0060.02518.46
5.6.100.0070.02318.37
5.6.90.0070.02418.42
5.6.80.0030.02518.00
5.6.70.0080.02017.95
5.6.60.0050.04018.07
5.6.50.0080.02318.02
5.6.40.0060.02018.05
5.6.30.0050.02418.00
5.6.20.0100.02718.10
5.6.10.0080.02117.94
5.6.00.0070.02017.91
5.5.380.0050.04517.96
5.5.370.0080.04018.17
5.5.360.0130.02018.02
5.5.350.0080.02418.14
5.5.340.0080.02218.21
5.5.330.0110.03818.21
5.5.320.0100.02018.25
5.5.310.0050.02518.33
5.5.300.0120.02818.33
5.5.290.0030.03918.29
5.5.280.0030.02618.21
5.5.270.0080.02218.34
5.5.260.0130.01718.14
5.5.250.0040.02418.25
5.5.240.0000.02817.96
5.5.230.0080.02017.99
5.5.220.0030.02817.87
5.5.210.0080.03317.91
5.5.200.0070.03717.95
5.5.190.0070.02217.88
5.5.180.0050.02817.94
5.5.170.0060.01315.61
5.5.160.0100.02117.91
5.5.150.0080.02817.88
5.5.140.0100.02117.95
5.5.130.0070.04017.91
5.5.120.0060.04617.79
5.5.110.0100.04117.97
5.5.100.0020.03217.84
5.5.90.0040.04217.88
5.5.80.0050.02817.93
5.5.70.0030.04717.74
5.5.60.0130.03217.88
5.5.50.0080.04017.76
5.5.40.0050.04217.77
5.5.30.0070.04017.83
5.5.20.0100.04617.85
5.5.10.0040.04317.84
5.5.00.0020.03617.84
5.4.450.0020.03916.00
5.4.440.0030.02315.90
5.4.430.0060.02015.66
5.4.420.0020.02515.90
5.4.410.0070.02115.84
5.4.400.0030.02315.83
5.4.390.0030.02015.74
5.4.380.0040.02015.72
5.4.370.0050.04215.80
5.4.360.0030.02515.78
5.4.350.0030.02515.68
5.4.340.0040.02415.70
5.4.330.0060.01012.32
5.4.320.0020.02615.82
5.4.310.0040.02315.74
5.4.300.0050.02115.69
5.4.290.0020.02315.76
5.4.280.0070.03215.71
5.4.270.0110.03315.81
5.4.260.0070.03715.88
5.4.250.0120.03515.78
5.4.240.0120.03615.80
5.4.230.0030.02815.67
5.4.220.0030.04215.58
5.4.210.0070.04015.85
5.4.200.0080.02515.62
5.4.190.0140.03315.69
5.4.180.0090.03515.73
5.4.170.0030.03015.61
5.4.160.0040.04115.63
5.4.150.0080.04015.83
5.4.140.0080.03514.40
5.4.130.0080.02314.40
5.4.120.0030.02614.46
5.4.110.0100.02214.42
5.4.100.0050.01814.54
5.4.90.0030.02814.45
5.4.80.0120.03714.40
5.4.70.0040.02714.42
5.4.60.0070.03814.37
5.4.50.0070.04014.29
5.4.40.0050.02714.50
5.4.30.0090.03514.42
5.4.20.0080.02314.38
5.4.10.0090.03214.36
5.4.00.0030.04714.22
5.3.290.0070.02713.89
5.3.280.0090.01913.73
5.3.270.0050.04113.78
5.3.260.0050.02813.82
5.3.250.0030.02613.73
5.3.240.0070.03513.63
5.3.230.0090.03713.83
5.3.220.0050.04613.90
5.3.210.0090.04113.72
5.3.200.0040.02213.81
5.3.190.0100.03913.85
5.3.180.0030.04313.82
5.3.170.0070.03313.88
5.3.160.0120.03413.82
5.3.150.0060.04113.85
5.3.140.0070.02713.79
5.3.130.0100.03613.84
5.3.120.0060.04113.85
5.3.110.0030.02613.80
5.3.100.0050.04113.63
5.3.90.0120.03113.61
5.3.80.0000.04313.49
5.3.70.0110.03513.52
5.3.60.0080.03813.74
5.3.50.0080.03613.54
5.3.40.0080.02913.49
5.3.30.0020.04513.46
5.3.20.0080.02813.37
5.3.10.0070.04213.19
5.3.00.0070.03613.17
5.2.170.0070.05711.31
5.2.160.0070.06311.23
5.2.150.0030.06711.08
5.2.140.0070.04711.28
5.2.130.0030.05311.21
5.2.120.0030.03711.27
5.2.110.0070.04311.02
5.2.100.0030.06011.25
5.2.90.0070.06311.27
5.2.80.0130.05711.02
5.2.70.0100.05711.18
5.2.60.0070.05711.14
5.2.50.0000.07011.07
5.2.40.0030.06011.04
5.2.30.0030.05010.98
5.2.20.0070.06011.00
5.2.10.0130.05010.91
5.2.00.0100.02310.85
5.1.60.0030.04710.59
5.1.50.0030.04010.59
5.1.40.0100.04710.59
5.1.30.0070.03310.59
5.1.20.0030.05710.59
5.1.10.0030.05010.59
5.1.00.0030.03010.59
5.0.50.0030.02710.59
5.0.40.0030.02310.59
5.0.30.0030.06310.59
5.0.20.0000.02710.59
5.0.10.0000.03010.59
5.0.00.0030.06310.59
4.4.90.0030.03310.59
4.4.80.0000.03710.59
4.4.70.0070.03310.59
4.4.60.0030.02310.59
4.4.50.0000.03710.59
4.4.40.0000.05310.59
4.4.30.0030.02010.59
4.4.20.0030.03310.59
4.4.10.0030.03710.59
4.4.00.0030.04010.59
4.3.110.0000.03310.59
4.3.100.0070.03010.59
4.3.90.0030.03010.59
4.3.80.0070.05010.59
4.3.70.0000.02010.59
4.3.60.0030.03310.59
4.3.50.0000.02010.59
4.3.40.0000.05010.59
4.3.30.0000.03710.59
4.3.20.0100.01710.59
4.3.10.0070.03010.59
4.3.00.0030.03010.59

preferences:
43.09 ms | 401 KiB | 5 Q