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((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).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0070.00718.43
8.3.50.0110.00818.18
8.3.40.0000.01518.84
8.3.30.0080.00819.04
8.3.20.0070.00020.34
8.3.10.0080.00023.48
8.3.00.0040.00419.79
8.2.180.0150.00016.50
8.2.170.0000.01522.96
8.2.160.0070.00720.44
8.2.150.0040.00424.18
8.2.140.0090.00024.66
8.2.130.0000.00726.16
8.2.120.0050.00321.08
8.2.110.0090.00020.96
8.2.100.0120.00017.84
8.2.90.0050.00318.16
8.2.80.0050.00317.97
8.2.70.0000.00817.63
8.2.60.0050.00318.05
8.2.50.0030.00618.07
8.2.40.0040.00718.16
8.2.30.0000.00918.20
8.2.20.0040.00417.88
8.2.10.0000.00819.75
8.2.00.0040.00417.73
8.1.270.0040.00423.66
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0040.00422.53
8.1.230.0060.00621.01
8.1.220.0080.00017.79
8.1.210.0040.00418.87
8.1.200.0080.00317.35
8.1.190.0000.00917.25
8.1.180.0050.00318.10
8.1.170.0060.00318.84
8.1.160.0000.00721.99
8.1.150.0000.00718.86
8.1.140.0040.00417.58
8.1.130.0000.00718.00
8.1.120.0040.00417.51
8.1.110.0000.00817.42
8.1.100.0040.00417.54
8.1.90.0000.00717.54
8.1.80.0070.00017.54
8.1.70.0070.00017.51
8.1.60.0000.00817.69
8.1.50.0050.00317.64
8.1.40.0000.00717.60
8.1.30.0050.00517.55
8.1.20.0040.00417.70
8.1.10.0050.00317.52
8.1.00.0070.00317.64
8.0.300.0080.00020.06
8.0.290.0000.00716.88
8.0.280.0000.00718.51
8.0.270.0030.00316.95
8.0.260.0060.00017.25
8.0.250.0040.00417.05
8.0.240.0040.00417.01
8.0.230.0030.00317.00
8.0.220.0000.00717.06
8.0.210.0030.00316.88
8.0.200.0000.00617.03
8.0.190.0050.00317.08
8.0.180.0060.00616.93
8.0.170.0050.00317.01
8.0.160.0070.00017.11
8.0.150.0000.00716.96
8.0.140.0040.00416.89
8.0.130.0070.00013.45
8.0.120.0040.00416.88
8.0.110.0050.00317.01
8.0.100.0040.00417.06
8.0.90.0040.00417.08
8.0.80.0100.00716.99
8.0.70.0050.00216.79
8.0.60.0040.00416.83
8.0.50.0000.00816.98
8.0.30.0070.01217.13
8.0.20.0150.00917.40
8.0.10.0030.00516.99
8.0.00.0050.01416.90
7.4.330.0000.00515.10
7.4.320.0000.00616.57
7.4.300.0000.00616.46
7.4.290.0070.00016.46
7.4.280.0000.00716.59
7.4.270.0000.00716.70
7.4.260.0030.00316.48
7.4.250.0040.00416.66
7.4.240.0020.00516.60
7.4.230.0070.00016.54
7.4.220.0090.00916.48
7.4.210.0040.01716.64
7.4.200.0000.00816.67
7.4.160.0090.00616.50
7.4.150.0100.01017.40
7.4.140.0090.00917.86
7.4.130.0090.00916.53
7.4.120.0130.00516.57
7.4.110.0130.00316.44
7.4.100.0100.00716.59
7.4.90.0110.01116.56
7.4.80.0210.00319.39
7.4.70.0120.00616.41
7.4.60.0060.00916.48
7.4.50.0000.00416.62
7.4.40.0100.00616.58
7.4.30.0100.00716.45
7.4.10.0030.01715.09
7.4.00.0070.01115.20
7.3.330.0000.00513.37
7.3.320.0000.00513.26
7.3.310.0000.00716.38
7.3.300.0050.00216.21
7.3.290.0070.00716.38
7.3.280.0110.00616.33
7.3.270.0080.01017.40
7.3.260.0040.01616.65
7.3.250.0080.01016.31
7.3.240.0060.01516.28
7.3.230.0150.00916.54
7.3.210.0120.00616.49
7.3.200.0120.00619.39
7.3.190.0160.00616.33
7.3.180.0130.00316.53
7.3.170.0090.01316.53
7.3.160.0060.01516.38
7.3.130.0100.00615.06
7.3.120.0080.00814.90
7.3.110.0060.01314.91
7.3.100.0070.00714.75
7.3.90.0030.01314.79
7.3.80.0030.01014.76
7.3.70.0030.01314.91
7.3.60.0060.00914.86
7.3.50.0090.00314.84
7.3.40.0060.00614.82
7.3.30.0030.01014.91
7.3.20.0070.00716.58
7.3.10.0060.00916.66
7.3.00.0090.00616.40
7.2.330.0070.01316.70
7.2.320.0040.01416.82
7.2.310.0100.00616.54
7.2.300.0070.01016.62
7.2.290.0080.00816.41
7.2.260.0160.00615.06
7.2.250.0080.01115.13
7.2.240.0150.00014.88
7.2.230.0120.00414.88
7.2.220.0030.00614.68
7.2.210.0000.01714.97
7.2.200.0110.00415.25
7.2.190.0080.00815.01
7.2.180.0000.01415.09
7.2.170.0060.01314.75
7.2.160.0060.00915.03
7.2.150.0030.01317.10
7.2.140.0000.01616.80
7.2.130.0040.00816.66
7.2.120.0080.00416.80
7.2.110.0030.00716.88
7.2.100.0060.00617.03
7.2.90.0070.00716.68
7.2.80.0000.01016.95
7.2.70.0000.00916.95
7.2.60.0090.00916.81
7.2.50.0090.00916.97
7.2.40.0000.00916.82
7.2.30.0030.01216.98
7.2.20.0030.00616.72
7.2.10.0060.00916.64
7.2.00.0070.00818.17
7.1.330.0030.01015.79
7.1.320.0030.01015.66
7.1.310.0030.01015.85
7.1.300.0000.01615.75
7.1.290.0100.00315.54
7.1.280.0030.01115.75
7.1.270.0070.00715.55
7.1.260.0040.01115.76
7.1.250.0070.00715.75
7.1.240.0060.00315.86
7.1.230.0000.01515.70
7.1.220.0050.00515.59
7.1.210.0050.00515.75
7.1.200.0020.01015.58
7.1.190.0060.00915.61
7.1.180.0040.00815.91
7.1.170.0090.00615.77
7.1.160.0040.00415.63
7.1.150.0060.00915.70
7.1.140.0030.00915.57
7.1.130.0060.01015.72
7.1.120.0070.00715.81
7.1.110.0120.00315.92
7.1.100.0060.00817.00
7.1.90.0080.00615.87
7.1.80.0100.00315.75
7.1.70.0040.00716.32
7.1.60.0070.00817.79
7.1.50.0160.00625.24
7.1.40.0000.00915.40
7.1.30.0030.01015.83
7.1.20.0040.00815.61
7.1.10.0110.00315.65
7.1.00.0040.04019.08
7.0.330.0040.00715.28
7.0.320.0050.00515.28
7.0.310.0040.00415.36
7.0.300.0060.00615.21
7.0.290.0090.00315.34
7.0.280.0080.00015.35
7.0.270.0040.00815.50
7.0.260.0030.01215.43
7.0.250.0070.00715.38
7.0.240.0040.00715.45
7.0.230.0120.00015.51
7.0.220.0070.00715.39
7.0.210.0000.01015.23
7.0.200.0020.00916.13
7.0.190.0030.00915.17
7.0.180.0050.00515.16
7.0.170.0000.01315.36
7.0.160.0060.00615.38
7.0.150.0030.00615.25
7.0.140.0110.03318.56
7.0.130.0120.00615.55
7.0.120.0050.00515.58
7.0.110.0030.02817.72
7.0.100.0070.04017.70
7.0.90.0030.04617.71
7.0.80.0030.04417.71
7.0.70.0020.02917.59
7.0.60.0080.02917.74
7.0.50.0050.04418.08
7.0.40.0060.02216.68
7.0.30.0030.02516.87
7.0.20.0030.02716.86
7.0.10.0030.02516.80
7.0.00.0050.03116.86
5.6.400.0100.00314.45
5.6.390.0030.00514.34
5.6.380.0000.01114.53
5.6.370.0040.00413.99
5.6.360.0000.01514.12
5.6.350.0120.00314.55
5.6.340.0040.00414.42
5.6.330.0030.01114.60
5.6.320.0060.00914.27
5.6.310.0030.00914.34
5.6.300.0080.00614.51
5.6.290.0040.01114.41
5.6.280.0080.03817.68
5.6.270.0060.00914.68
5.6.260.0070.02517.55
5.6.250.0100.02317.55
5.6.240.0030.02917.49
5.6.230.0050.02617.51
5.6.220.0070.04517.60
5.6.210.0070.03517.49
5.6.200.0110.02117.60
5.6.190.0020.02817.79
5.6.180.0110.03217.96
5.6.170.0050.02617.65
5.6.160.0080.03817.74
5.6.150.0000.03017.68
5.6.140.0040.02517.67
5.6.130.0060.02517.71
5.6.120.0100.02017.79
5.6.110.0050.03417.77
5.6.100.0080.04117.60
5.6.90.0020.02517.91
5.6.80.0070.02517.23
5.6.70.0130.01717.40
5.6.60.0090.03917.44
5.6.50.0030.04217.24
5.6.40.0070.04217.34
5.6.30.0030.04217.36
5.6.20.0070.04617.39
5.6.10.0070.04217.33
5.6.00.0050.04217.26
5.5.380.0050.04717.27
5.5.370.0090.03617.33
5.5.360.0100.04017.34
5.5.350.0060.03817.43
5.5.340.0020.02617.67
5.5.330.0040.02717.60
5.5.320.0080.02217.65
5.5.310.0050.04517.41
5.5.300.0070.02417.55
5.5.290.0030.02717.49
5.5.280.0080.02217.77
5.5.270.0070.03317.44
5.5.260.0030.02617.52
5.5.250.0070.02217.45
5.5.240.0060.02317.12
5.5.230.0080.03517.35
5.5.220.0050.04317.17
5.5.210.0090.04317.19
5.5.200.0080.04317.16
5.5.190.0060.04317.04
5.5.180.0130.03817.01
5.5.170.0040.01114.15
5.5.160.0100.02317.13
5.5.150.0090.03117.25
5.5.140.0080.03517.26
5.5.130.0030.04317.28
5.5.120.0110.04117.15
5.5.110.0070.04417.26
5.5.100.0060.04517.17
5.5.90.0120.03817.12
5.5.80.0020.03917.22
5.5.70.0060.04317.11
5.5.60.0070.04217.21
5.5.50.0080.04217.13
5.5.40.0070.04317.14
5.5.30.0140.03417.24
5.5.20.0070.04117.04
5.5.10.0070.04117.08
5.5.00.0080.04217.25
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

preferences:
55.05 ms | 400 KiB | 5 Q