3v4l.org

run code in 300+ PHP versions simultaneously
<?php function base62encode($data) { $outstring = ''; $l = strlen($data); for ($i = 0; $i < $l; $i += 8) { $chunk = substr($data, $i, 8); $outlen = ceil((strlen($chunk) * 8)/6); //8bit/char in, 6bits/char out, round up $x = bin2hex($chunk); //gmp won't convert from binary, so go via hex $w = gmp_strval(gmp_init(ltrim($x, '0'), 16), 62); //gmp doesn't like leading 0s $pad = str_pad($w, $outlen, '0', STR_PAD_LEFT); $outstring .= $pad; } return $outstring; } /** * Decode base-62 encoded text into binary * Note that because base-62 encodes slightly less than 6 bits per character (actually 5.95419631038688), there is some wastage * In order to make this practical, we chunk in groups of up to 11 input chars, which give up to 8 output chars * with a wastage of up to 4 bits per chunk, so while the output is not quite as space efficient as a * true multiprecision conversion, it's orders of magnitude faster * Note that the input of this function is not compatible with that of a multiprecision conversion, but it's a practical encoding implementation * The encoding overhead tends towards 37.5% with this chunk size; bigger chunk sizes can be slightly more space efficient, but may be slower * Base-64 doesn't suffer this problem because it fits into exactly 6 bits, so it generates the same results as a multiprecision conversion * Requires PHP 5.3.2 and gmp 4.2.0 * @param string $data Base-62 encoded text (not chunked or split) * @return string Decoded binary data */ function base62decode($data) { $outstring = ''; $l = strlen($data); for ($i = 0; $i < $l; $i += 11) { $chunk = substr($data, $i, 11); $outlen = floor((strlen($chunk) * 6)/8); //6bit/char in, 8bits/char out, round down $y = gmp_strval(gmp_init(ltrim($chunk, '0'), 62), 16); //gmp doesn't like leading 0s $pad = str_pad($y, $outlen * 2, '0', STR_PAD_LEFT); //double output length as as we're going via hex (4bits/char) $outstring .= pack('H*', $pad); //same as hex2bin } return $outstring; } $data = "?1,2,3,45,4536,1234567"; $encode = base62encode($data); echo 'Encode: '.$encode; echo ' - '.base62decode($encode);

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.0150.00718.43
8.3.50.0070.00718.28
8.3.40.0110.00318.96
8.3.30.0080.00819.06
8.3.20.0060.00320.33
8.3.10.0040.00420.65
8.3.00.0080.00020.79
8.2.180.0090.00917.00
8.2.170.0140.00722.96
8.2.160.0140.00020.48
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0000.00819.48
8.2.120.0080.00026.35
8.2.110.0040.00721.20
8.2.100.0070.00418.16
8.2.90.0000.00819.63
8.2.80.0080.00017.97
8.2.70.0030.00517.88
8.2.60.0000.00818.30
8.2.50.0000.00818.10
8.2.40.0030.00620.84
8.2.30.0000.00719.66
8.2.20.0050.00317.89
8.2.10.0000.00718.42
8.2.00.0000.00818.40
8.1.280.0110.00625.92
8.1.270.0000.01024.01
8.1.260.0070.00028.09
8.1.250.0080.00028.09
8.1.240.0050.00519.45
8.1.230.0060.00619.91
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0060.00317.63
8.1.190.0060.00317.48
8.1.180.0040.00418.10
8.1.170.0040.00418.81
8.1.160.0000.00721.18
8.1.150.0020.00519.05
8.1.140.0000.00819.70
8.1.130.0000.00717.68
8.1.120.0030.00317.55
8.1.110.0040.00417.54
8.1.100.0000.00817.73
8.1.90.0000.00717.73
8.1.80.0000.00817.52
8.1.70.0000.00717.54
8.1.60.0040.00417.71
8.1.50.0070.00317.75
8.1.40.0000.00917.68
8.1.30.0040.00417.86
8.1.20.0000.00817.95
8.1.10.0000.00717.63
8.1.00.0040.00417.59
8.0.300.0050.00218.77
8.0.290.0000.00816.88
8.0.280.0040.00418.67
8.0.270.0070.00017.54
8.0.260.0000.00716.99
8.0.250.0070.00017.17
8.0.240.0000.00717.26
8.0.230.0050.00317.12
8.0.220.0030.00617.16
8.0.210.0000.00717.20
8.0.200.0000.00817.15
8.0.190.0000.00817.29
8.0.180.0070.00017.04
8.0.170.0050.00217.10
8.0.160.0060.00317.16
8.0.150.0000.00817.03
8.0.140.0000.00817.06
8.0.130.0030.00313.30
8.0.120.0090.00017.07
8.0.110.0040.00417.09
8.0.100.0000.00717.24
8.0.90.0040.00416.93
8.0.80.0090.00617.05
8.0.70.0070.00016.95
8.0.60.0040.00417.05
8.0.50.0020.00517.13
8.0.30.0090.00817.32
8.0.20.0090.01117.43
8.0.10.0040.00417.11
8.0.00.0120.01116.83
7.4.330.0000.00415.08
7.4.320.0000.00616.67
7.4.300.0000.00616.70
7.4.290.0040.00416.67
7.4.280.0060.00516.87
7.4.270.0000.00716.64
7.4.260.0000.00716.62
7.4.250.0030.00316.72
7.4.240.0030.00316.77
7.4.230.0050.00316.78
7.4.220.0080.01216.86
7.4.210.0090.00616.79
7.4.200.0040.00416.79
7.4.160.0040.01216.64
7.4.150.0000.01717.40
7.4.140.0100.01117.86
7.4.130.0110.00916.67
7.4.120.0060.01016.76
7.4.110.0070.01116.80
7.4.100.0120.00616.88
7.4.90.0170.00016.79
7.4.80.0090.00919.39
7.4.70.0070.01016.63
7.4.60.0070.01016.82
7.4.50.0140.00316.78
7.4.40.0100.00716.64
7.4.30.0110.00716.81
7.4.00.0030.01315.22
7.3.330.0030.00413.32
7.3.320.0050.00213.46
7.3.310.0000.00716.69
7.3.300.0060.00016.53
7.3.290.0040.00416.58
7.3.280.0110.00616.60
7.3.270.0120.00617.40
7.3.260.0100.00716.64
7.3.250.0120.01316.71
7.3.240.0080.01216.79
7.3.230.0060.01216.54
7.3.210.0090.00916.58
7.3.200.0070.01019.39
7.3.190.0100.00616.83
7.3.180.0100.00716.85
7.3.170.0040.01316.51
7.3.160.0090.00616.60
7.3.10.0080.00716.82
7.3.00.0090.00716.71
7.2.330.0120.00616.75
7.2.320.0100.00716.89
7.2.310.0160.00917.02
7.2.300.0120.00916.86
7.2.290.0140.00716.74
7.2.130.0020.01117.11
7.2.120.0100.00717.24
7.2.110.0030.00917.13
7.2.100.0080.00516.96
7.2.90.0030.01116.97
7.2.80.0070.00516.99
7.2.70.0080.00817.16
7.2.60.0040.01117.06
7.2.50.0050.00716.92
7.2.40.0030.00816.84
7.2.30.0060.00917.23
7.2.20.0060.00816.86
7.2.10.0050.00717.14
7.2.00.0050.00917.91
7.1.250.0050.00915.99
7.1.200.0110.00415.97
7.1.100.0030.00918.53
7.1.70.0000.00717.15
7.1.60.0100.01419.27
7.1.50.0040.01217.30
7.1.00.0100.07022.61
7.0.200.0000.00717.04
7.0.60.0230.07320.05
7.0.50.0000.04318.14
7.0.40.0100.08020.38
7.0.30.0170.05320.46
7.0.20.0300.05320.30
7.0.10.0170.06720.39
7.0.00.0170.07720.32
5.6.280.0030.07321.30
5.6.210.0070.07020.54
5.6.200.0030.04018.42
5.6.190.0100.07720.57
5.6.180.0070.06320.55
5.6.170.0270.06320.77
5.6.160.0000.04720.66
5.6.150.0100.08018.29
5.6.140.0030.03718.39
5.6.130.0030.04018.38
5.6.120.0070.04721.32
5.6.110.0030.08021.21
5.6.100.0030.05721.31
5.6.90.0000.09021.14
5.6.80.0100.08020.49
5.5.350.0270.04720.50
5.5.340.0100.07318.08
5.5.330.0070.06320.56
5.5.320.0300.07020.53
5.5.310.0170.04720.52
5.5.300.0300.04018.27
5.5.290.0070.06018.08
5.5.280.0170.07320.91
5.5.270.0130.08320.90
5.5.260.0070.04020.81
5.5.250.0030.08320.68
5.5.240.0130.03020.47

preferences:
76.09 ms | 401 KiB | 5 Q