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($v); $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): return 'null'; case is_string($value): return '"' . _js_uc_esc($value) . '"'; default: return $value; } } 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, ), 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.0070.00718.18
8.3.50.0100.01021.93
8.3.40.0140.00018.89
8.3.30.0120.00320.29
8.3.20.0000.00918.77
8.3.10.0060.00321.09
8.3.00.0050.00319.69
8.2.180.0160.00616.88
8.2.170.0090.00622.96
8.2.160.0110.00720.39
8.2.150.0050.00324.18
8.2.140.0060.00324.66
8.2.130.0080.00026.16
8.2.120.0050.00219.89
8.2.110.0000.00920.35
8.2.100.0040.00817.91
8.2.90.0040.00418.22
8.2.80.0060.00319.26
8.2.70.0040.00417.50
8.2.60.0030.00517.93
8.2.50.0040.00418.07
8.2.40.0000.00819.78
8.2.30.0050.00221.20
8.2.20.0070.00017.85
8.2.10.0000.00817.80
8.2.00.0040.00417.80
8.1.280.0100.00725.92
8.1.270.0080.00023.99
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0070.00319.13
8.1.230.0040.00720.71
8.1.220.0030.00617.74
8.1.210.0050.00519.04
8.1.200.0070.00317.48
8.1.190.0000.00917.52
8.1.180.0060.00318.10
8.1.170.0060.00318.71
8.1.160.0000.00718.95
8.1.150.0000.00818.70
8.1.140.0000.00717.52
8.1.130.0030.00317.93
8.1.120.0000.00717.40
8.1.110.0040.00417.41
8.1.100.0000.00817.61
8.1.90.0000.00717.54
8.1.80.0000.00817.55
8.1.70.0070.00017.45
8.1.60.0050.00517.65
8.1.50.0040.00417.60
8.1.40.0040.00417.59
8.1.30.0040.00417.71
8.1.20.0040.00417.69
8.1.10.0050.00317.67
8.1.00.0060.00617.62
8.0.300.0070.00020.29
8.0.290.0070.00017.18
8.0.280.0000.00718.46
8.0.270.0040.00416.90
8.0.260.0030.00316.94
8.0.250.0030.00316.98
8.0.240.0000.00717.00
8.0.230.0070.00017.02
8.0.220.0030.00316.91
8.0.210.0040.00417.07
8.0.200.0000.00616.97
8.0.190.0070.00016.94
8.0.180.0030.00517.05
8.0.170.0050.00317.02
8.0.160.0000.00817.04
8.0.150.0040.00417.00
8.0.140.0070.00016.98
8.0.130.0070.00013.52
8.0.120.0030.00616.97
8.0.110.0000.00716.88
8.0.100.0000.00717.01
8.0.90.0000.00716.86
8.0.80.0090.00616.94
8.0.70.0050.00216.98
8.0.60.0000.00716.97
8.0.50.0040.00417.00
8.0.30.0130.00517.19
8.0.20.0110.00717.40
8.0.10.0040.00417.02
8.0.00.0100.00816.88
7.4.330.0000.00516.70
7.4.320.0050.00316.71
7.4.300.0040.00416.55
7.4.290.0080.00016.61
7.4.280.0070.00016.57
7.4.270.0080.00016.66
7.4.260.0060.00013.30
7.4.250.0000.00816.64
7.4.240.0000.00716.65
7.4.230.0070.00016.55
7.4.220.0090.00916.46
7.4.210.0070.00916.68
7.4.200.0050.00216.48
7.4.190.0030.00316.70
7.4.160.0130.00316.64
7.4.150.0040.01417.40
7.4.140.0080.01117.86
7.4.130.0130.00816.43
7.4.120.0150.00316.58
7.4.110.0120.00816.71
7.4.100.0090.00916.55
7.4.90.0160.01316.55
7.4.80.0110.00619.39
7.4.70.0060.01416.52
7.4.60.0090.00816.55
7.4.50.0000.00816.61
7.4.40.0050.01022.77
7.4.30.0110.01316.44
7.4.00.0060.00914.78
7.3.330.0030.00313.36
7.3.320.0030.00313.31
7.3.310.0020.00516.18
7.3.300.0030.00316.31
7.3.290.0160.00016.43
7.3.280.0070.00916.37
7.3.270.0100.00717.40
7.3.260.0110.00918.24
7.3.250.0100.01116.38
7.3.240.0160.00016.47
7.3.230.0090.00916.61
7.3.210.0040.01916.39
7.3.200.0060.01319.39
7.3.190.0030.01516.42
7.3.180.0000.01916.34
7.3.170.0160.00016.50
7.3.160.0040.01216.47
7.3.120.0060.01014.70
7.3.110.0200.00014.82
7.3.100.0080.00414.75
7.3.90.0060.00814.83
7.3.80.0110.00714.73
7.3.70.0060.00614.63
7.3.60.0040.00814.62
7.3.50.0030.01014.54
7.3.40.0120.00314.67
7.3.30.0040.00814.42
7.3.20.0150.00316.63
7.3.10.0050.01016.67
7.3.00.0100.00516.62
7.2.330.0140.00316.70
7.2.320.0030.01416.65
7.2.310.0070.01116.70
7.2.300.0090.01116.71
7.2.290.0160.00016.74
7.2.250.0060.01214.91
7.2.240.0100.00614.68
7.2.230.0060.00915.16
7.2.220.0030.01314.81
7.2.210.0090.00914.85
7.2.200.0060.00915.04
7.2.190.0000.01515.18
7.2.180.0100.00315.00
7.2.170.0090.00615.08
7.2.160.0040.01415.06
7.2.150.0000.01316.50
7.2.140.0030.01416.86
7.2.130.0060.00816.73
7.2.120.0050.01016.70
7.2.110.0040.00816.60
7.2.100.0080.00816.69
7.2.90.0050.01216.75
7.2.80.0090.00516.82
7.2.70.0090.01016.97
7.2.60.0080.01016.78
7.2.50.0110.00816.87
7.2.40.0090.00516.95
7.2.30.0050.01116.85
7.2.20.0020.01316.59
7.2.10.0050.00916.77
7.2.00.0020.01217.50
7.1.330.0110.00815.63
7.1.320.0060.00915.64
7.1.310.0090.00915.58
7.1.300.0090.00615.66
7.1.290.0030.00715.48
7.1.280.0000.01015.73
7.1.270.0100.00715.74
7.1.260.0040.01115.79
7.1.250.0030.00715.54
7.1.240.0140.00015.49
7.1.230.0000.01715.61
7.1.220.0070.01015.68
7.1.210.0000.01215.72
7.1.200.0100.00715.45
7.1.190.0090.00015.59
7.1.180.0030.01015.59
7.1.170.0080.00715.65
7.1.160.0060.00915.74
7.1.150.0110.00415.69
7.1.140.0080.00415.80
7.1.130.0030.00715.64
7.1.120.0030.01415.64
7.1.110.0100.00315.71
7.1.100.0030.00816.99
7.1.90.0060.00615.84
7.1.80.0150.00015.73
7.1.70.0020.00816.22
7.1.60.0080.01217.46
7.1.50.0030.01116.02
7.1.40.0040.00715.43
7.1.30.0060.00915.75
7.1.20.0040.01115.62
7.1.10.0030.00915.55
7.1.00.0050.02519.07
7.0.330.0030.01015.32
7.0.320.0070.00715.23
7.0.310.0030.00915.47
7.0.300.0030.00915.20
7.0.290.0030.01015.46
7.0.280.0050.00515.41
7.0.270.0100.00715.27
7.0.260.0090.00715.07
7.0.250.0050.00515.37
7.0.240.0110.00315.17
7.0.230.0070.00315.32
7.0.220.0000.01315.45
7.0.210.0060.00815.30
7.0.200.0030.00516.01
7.0.190.0040.01215.32
7.0.180.0090.00315.00
7.0.170.0090.00615.32
7.0.160.0030.00915.52
7.0.150.0050.00315.18
7.0.140.0070.04218.84
7.0.130.0070.01115.21
7.0.120.0070.00315.01
7.0.110.0030.01115.33
7.0.100.0090.00615.26
7.0.90.0310.04317.48
7.0.80.0220.04217.73
7.0.70.0360.04017.51
7.0.60.0300.04317.64
7.0.50.0310.04117.89
7.0.40.0070.03916.71
7.0.30.0100.02816.70
7.0.20.0080.04716.85
7.0.10.0060.04216.81
7.0.00.0070.03016.73
5.6.400.0000.01514.33
5.6.390.0040.00814.52
5.6.380.0100.00314.38
5.6.370.0030.00714.16
5.6.360.0000.00914.54
5.6.350.0080.00414.15
5.6.340.0050.00514.57
5.6.330.0060.01014.41
5.6.320.0090.00313.95
5.6.310.0030.01214.38
5.6.300.0070.01114.65
5.6.290.0090.00914.32
5.6.280.0060.03817.57
5.6.270.0000.01514.07
5.6.260.0090.00614.21
5.6.250.0110.00314.39
5.6.240.0040.04917.35
5.6.230.0080.04517.38
5.6.220.0070.03517.54
5.6.210.0060.04617.41
5.6.200.0050.03417.59
5.6.190.0070.03717.74
5.6.180.0070.04817.80
5.6.170.0070.03817.54
5.6.160.0080.04517.64
5.6.150.0100.03017.64
5.6.140.0020.02817.66
5.6.130.0130.04217.65
5.6.120.0050.03817.66
5.6.110.0090.04717.51
5.6.100.0080.04617.70
5.6.90.0080.03617.73
5.6.80.0050.04717.40
5.6.70.0070.03017.23
5.6.60.0070.04417.30
5.6.50.0090.03617.47
5.6.40.0140.03717.38
5.6.30.0050.04217.39
5.6.20.0080.02517.34
5.6.10.0050.04317.30
5.6.00.0030.04117.31
5.5.380.0020.04717.23
5.5.370.0070.04417.41
5.5.360.0080.04117.27
5.5.350.0130.03817.35
5.5.340.0060.04617.57
5.5.330.0120.04017.38
5.5.320.0040.02617.58
5.5.310.0070.04817.36
5.5.300.0090.02117.66
5.5.290.0050.02717.72
5.5.280.0080.04117.49
5.5.270.0100.04617.57
5.5.260.0060.02817.54
5.5.250.0050.04617.22
5.5.240.0040.04717.33
5.5.230.0060.03817.25
5.5.220.0120.03517.22
5.5.210.0050.03317.25
5.5.200.0080.02217.22
5.5.190.0090.02717.09
5.5.180.0120.02517.19
5.5.170.0100.00314.32
5.5.160.0090.03817.21
5.5.150.0050.04117.26
5.5.140.0070.02817.16
5.5.130.0080.04217.23
5.5.120.0050.03817.07
5.5.110.0120.03817.20
5.5.100.0070.02517.22
5.5.90.0140.02317.14
5.5.80.0100.03817.12
5.5.70.0080.03717.18
5.5.60.0070.04517.08
5.5.50.0120.02217.12
5.5.40.0080.03817.08
5.5.30.0120.03016.98
5.5.20.0000.02917.19
5.5.10.0090.02617.04
5.5.00.0020.04917.15
5.4.450.0080.03315.24
5.4.440.0020.03315.21
5.4.430.0100.04015.22
5.4.420.0100.02115.29
5.4.410.0070.04015.00
5.4.400.0050.04114.96
5.4.390.0070.04015.01
5.4.380.0040.04215.10
5.4.370.0070.04014.96
5.4.360.0050.02715.11
5.4.350.0070.03414.83
5.4.340.0050.04015.06
5.4.330.0070.00310.76
5.4.320.0050.04214.93
5.4.310.0080.04014.98
5.4.300.0070.03814.90
5.4.290.0070.03614.92
5.4.280.0100.02214.88
5.4.270.0040.03815.02
5.4.260.0070.03315.01
5.4.250.0130.03514.95
5.4.240.0050.03814.83
5.4.230.0000.04515.03
5.4.220.0030.04515.07
5.4.210.0020.02314.98
5.4.200.0130.03614.95
5.4.190.0070.02514.93
5.4.180.0030.02414.93
5.4.170.0070.02815.06
5.4.160.0070.03814.83
5.4.150.0050.03014.92
5.4.140.0070.02013.71
5.4.130.0090.03513.54
5.4.120.0020.03913.68
5.4.110.0040.04213.66
5.4.100.0030.03113.66
5.4.90.0080.04013.58
5.4.80.0080.03513.62
5.4.70.0050.02213.59
5.4.60.0080.03613.64
5.4.50.0040.02913.78
5.4.40.0030.04013.68
5.4.30.0070.03413.72
5.4.20.0020.03913.77
5.4.10.0050.02213.66
5.4.00.0080.02813.49
5.3.290.0080.03812.72
5.3.280.0040.04412.66
5.3.270.0080.03812.74
5.3.260.0070.03812.71
5.3.250.0100.02312.69
5.3.240.0030.02812.76
5.3.230.0040.02712.74
5.3.220.0030.04212.68
5.3.210.0050.03012.65
5.3.200.0110.02512.67
5.3.190.0100.03612.75
5.3.180.0080.03512.68
5.3.170.0050.04012.65
5.3.160.0040.04112.71
5.3.150.0080.03912.64
5.3.140.0050.04012.70
5.3.130.0060.04012.73
5.3.120.0070.04412.67
5.3.110.0050.04012.64
5.3.100.0070.03012.38
5.3.90.0070.03712.43
5.3.80.0050.03712.45
5.3.70.0030.02312.35
5.3.60.0060.03912.39
5.3.50.0070.03312.41
5.3.40.0070.03812.31
5.3.30.0030.02412.31
5.3.20.0050.03812.27
5.3.10.0050.03812.19
5.3.00.0050.03612.24
5.2.170.0030.06311.11
5.2.160.0070.04011.22
5.2.150.0030.04311.25
5.2.140.0000.06311.16
5.2.130.0030.03311.05
5.2.120.0130.04011.25
5.2.110.0070.04011.16
5.2.100.0070.06011.15
5.2.90.0070.05010.99
5.2.80.0030.06711.15
5.2.70.0000.06711.01
5.2.60.0000.05311.15
5.2.50.0030.06311.18
5.2.40.0130.02710.96
5.2.30.0030.05710.93
5.2.20.0030.06011.04
5.2.10.0000.04710.96
5.2.00.0000.06310.74
5.1.60.0070.04710.12
5.1.50.0070.05010.13
5.1.40.0100.04310.08
5.1.30.0030.05710.29
5.1.20.0000.06310.50
5.1.10.0070.05010.20
5.1.00.0000.06010.16
5.0.50.0030.0308.69
5.0.40.0030.0208.46
5.0.30.0000.0438.28
5.0.20.0070.0438.36
5.0.10.0030.0438.11
5.0.00.0030.0608.20
4.4.90.0030.0307.42
4.4.80.0030.0377.42
4.4.70.0030.0377.42
4.4.60.0000.0377.42
4.4.50.0030.0337.42
4.4.40.0000.0577.42
4.4.30.0100.0277.42
4.4.20.0030.0377.42
4.4.10.0000.0277.42
4.4.00.0030.0377.42
4.3.110.0030.0177.42
4.3.100.0000.0337.42
4.3.90.0000.0337.42
4.3.80.0030.0507.42
4.3.70.0000.0407.42
4.3.60.0000.0277.42
4.3.50.0000.0407.42
4.3.40.0000.0437.42
4.3.30.0000.0377.42
4.3.20.0000.0407.42
4.3.10.0000.0307.42
4.3.00.0030.0337.42

preferences:
43.94 ms | 401 KiB | 5 Q