3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Crypt { /* Key: Next prime greater than 62 ^ n / 1.618033988749894848 */ /* Value: modular multiplicative inverse */ private static $golden_primes = array( '1' => '1', '41' => '59', '2377' => '1677', '147299' => '187507', '9132313' => '5952585', '566201239' => '643566407', '35104476161' => '22071637057', '2176477521929' => '294289236153', '134941606358731' => '88879354792675', '8366379594239857' => '7275288500431249', '518715534842869223' => '280042546585394647' ); /* Ascii : 0 9, A Z, a z */ /* $chars = array_merge(range(48,57), range(65,90), range(97,122)) */ private static $chars62 = array( 0=>48,1=>49,2=>50,3=>51,4=>52,5=>53,6=>54,7=>55,8=>56,9=>57,10=>65, 11=>66,12=>67,13=>68,14=>69,15=>70,16=>71,17=>72,18=>73,19=>74,20=>75, 21=>76,22=>77,23=>78,24=>79,25=>80,26=>81,27=>82,28=>83,29=>84,30=>85, 31=>86,32=>87,33=>88,34=>89,35=>90,36=>97,37=>98,38=>99,39=>100,40=>101, 41=>102,42=>103,43=>104,44=>105,45=>106,46=>107,47=>108,48=>109,49=>110, 50=>111,51=>112,52=>113,53=>114,54=>115,55=>116,56=>117,57=>118,58=>119, 59=>120,60=>121,61=>122 ); public static function base62($int) { $key = ""; while(bccomp($int, 0) > 0) { $mod = bcmod($int, 62); $key .= chr(self::$chars62[$mod]); $int = bcdiv($int, 62); } return strrev($key); } public static function hash($num, $len = 5) { $ceil = bcpow(62, $len); $primes = array_keys(self::$golden_primes); $prime = $primes[$len]; $dec = bcmod(bcmul($num, $prime), $ceil); $hash = self::base62($dec); return str_pad($hash, $len, "0", STR_PAD_LEFT); } public static function unbase62($key) { $int = 0; foreach(str_split(strrev($key)) as $i => $char) { $dec = array_search(ord($char), self::$chars62); $int = bcadd(bcmul($dec, bcpow(62, $i)), $int); } return $int; } public static function unhash($hash) { $len = strlen($hash); $ceil = bcpow(62, $len); $mmiprimes = array_values(self::$golden_primes); $mmi = $mmiprimes[$len]; $num = self::unbase62($hash); $dec = bcmod(bcmul($num, $mmi), $ceil); return $dec; } } $hashParams = array( 'plopi' => 'gato', 'token' => 'lol' ); var_dump($hashParams); $hashParams = 46521; $strEncoded = Crypt::hash(json_encode($hashParams)); echo "\n encoded\t:" . json_encode($hashParams). "\n"; echo "\n encoded\t:" . $strEncoded. "\n"; echo "\n decode encoded\t:" . Crypt::unhash($strEncoded)."\n"; var_dump(json_decode(Crypt::unhash($strEncoded), true));

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.0040.01418.43
8.3.50.0140.00721.99
8.3.40.0030.01718.62
8.3.30.0090.00619.21
8.3.20.0080.00020.33
8.3.10.0090.00021.75
8.3.00.0040.00419.13
8.2.180.0190.00318.54
8.2.170.0080.01122.96
8.2.160.0070.00722.20
8.2.150.0090.00624.18
8.2.140.0060.00324.66
8.2.130.0040.00426.16
8.2.120.0030.00519.66
8.2.110.0060.00322.08
8.2.100.0040.00718.34
8.2.90.0090.00019.36
8.2.80.0080.00017.97
8.2.70.0060.00317.50
8.2.60.0060.00617.93
8.2.50.0030.00618.07
8.2.40.0040.00418.28
8.2.30.0080.00018.19
8.2.20.0080.00317.74
8.2.10.0000.00918.05
8.2.00.0040.00417.92
8.1.280.0040.01125.92
8.1.270.0090.00019.01
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0080.00322.14
8.1.230.0060.00617.77
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0060.00317.48
8.1.190.0050.00317.35
8.1.180.0040.00418.10
8.1.170.0040.00418.78
8.1.160.0040.00422.01
8.1.150.0080.00018.90
8.1.140.0000.00819.23
8.1.130.0030.00317.86
8.1.120.0000.00717.54
8.1.110.0040.00417.57
8.1.100.0040.00417.52
8.1.90.0040.00417.45
8.1.80.0000.00717.46
8.1.70.0050.00317.52
8.1.60.0100.00017.70
8.1.50.0040.00417.45
8.1.40.0000.00917.41
8.1.30.0030.00617.73
8.1.20.0000.00717.75
8.1.10.0000.00717.63
8.1.00.0050.00217.58
8.0.300.0060.00318.77
8.0.290.0000.00716.63
8.0.280.0040.00418.46
8.0.270.0070.00017.25
8.0.260.0040.00417.19
8.0.250.0040.00417.03
8.0.240.0040.00416.99
8.0.230.0030.00317.01
8.0.220.0070.00016.88
8.0.210.0030.00316.93
8.0.200.0060.00316.85
8.0.190.0040.00417.05
8.0.180.0070.00317.00
8.0.170.0000.00816.97
8.0.160.0040.00416.94
8.0.150.0000.00716.80
8.0.140.0030.00516.93
8.0.130.0000.00513.26
8.0.120.0000.00816.88
8.0.110.0040.00416.96
8.0.100.0000.00816.99
8.0.90.0050.00216.83
8.0.80.0120.00316.89
8.0.70.0050.00316.89
8.0.60.0040.00416.89
8.0.50.0030.00516.79
8.0.30.0150.00517.30
8.0.20.0110.00817.40
8.0.10.0080.00017.09
8.0.00.0070.01016.77
7.4.330.0050.00015.03
7.4.320.0030.00316.46
7.4.300.0000.00716.57
7.4.290.0040.00416.66
7.4.280.0000.00816.54
7.4.270.0030.00316.59
7.4.260.0000.00816.62
7.4.250.0000.00716.54
7.4.240.0020.00516.55
7.4.230.0040.00416.31
7.4.220.0150.00316.64
7.4.210.0090.00616.43
7.4.200.0050.00316.64
7.4.160.0080.00816.61
7.4.150.0180.00317.40
7.4.140.0110.00717.86
7.4.130.0090.00916.55
7.4.120.0040.01416.48
7.4.110.0090.00916.44
7.4.100.0130.00616.56
7.4.90.0110.00716.45
7.4.80.0100.01319.39
7.4.70.0110.00816.61
7.4.60.0080.00916.73
7.4.50.0000.00616.39
7.4.40.0140.00416.30
7.4.30.0110.01116.64
7.4.00.0120.00714.90
7.3.330.0030.00313.24
7.3.320.0000.00513.26
7.3.310.0040.00416.44
7.3.300.0000.00716.29
7.3.290.0050.00916.39
7.3.280.0070.01216.39
7.3.270.0050.01317.40
7.3.260.0120.00616.47
7.3.250.0140.00316.44
7.3.240.0060.01316.47
7.3.230.0100.01316.71
7.3.210.0090.00916.56
7.3.200.0130.00619.39
7.3.190.0060.01016.64
7.3.180.0080.00816.64
7.3.170.0150.00616.32
7.3.160.0110.00716.43
7.3.120.0050.01014.75
7.3.110.0060.01214.92
7.3.100.0060.00914.88
7.3.90.0070.00915.04
7.3.80.0060.00914.81
7.3.70.0040.00614.78
7.3.60.0130.00414.83
7.3.50.0030.01014.94
7.3.40.0090.00414.84
7.3.30.0070.00714.90
7.3.20.0070.00816.56
7.3.10.0010.01216.47
7.3.00.0090.00716.72
7.2.330.0180.00016.65
7.2.320.0190.00016.56
7.2.310.0090.00916.52
7.2.300.0140.00416.80
7.2.290.0110.00616.54
7.2.250.0100.01015.09
7.2.240.0110.00715.14
7.2.230.0050.01414.87
7.2.220.0070.00815.21
7.2.210.0090.00914.95
7.2.200.0080.00515.14
7.2.190.0050.01215.01
7.2.180.0100.00614.96
7.2.170.0050.01115.03
7.2.60.0090.00317.08
7.1.330.0070.00715.72
7.1.320.0080.00515.88
7.1.310.0080.00815.94
7.1.300.0050.01015.83
7.1.290.0050.00915.73
7.1.280.0030.01215.90
7.1.270.0040.00915.85
7.1.260.0040.00915.90
7.1.200.0190.00415.43
7.1.70.0000.00817.34
7.1.60.0000.01317.38
7.1.50.0100.01616.97
7.1.00.0100.07022.51
7.0.200.0040.01516.67
7.0.140.0070.03021.95
7.0.90.0100.04720.01
7.0.80.0130.03719.91
7.0.70.0270.04319.96
7.0.60.0170.05719.88
7.0.50.0130.06020.37
7.0.40.0070.03320.11
7.0.30.0030.04720.18
7.0.20.0030.05720.18
7.0.10.0070.04720.12
7.0.00.0130.07720.09
5.6.280.0000.09321.11
5.6.240.0000.06020.67
5.6.230.0000.06020.77
5.6.220.0130.04020.65
5.6.210.0000.04320.70
5.6.200.0030.05021.12
5.6.190.0030.04721.07
5.6.180.0130.03721.07
5.6.170.0070.04020.99
5.6.160.0030.08321.04
5.6.150.0070.04321.14
5.6.140.0130.04020.98
5.6.130.0100.03321.07
5.6.120.0130.08721.05
5.6.110.0070.05321.07
5.6.100.0070.03321.12
5.6.90.0030.07721.11
5.6.80.0270.06020.35
5.6.70.0100.07720.42
5.6.60.0130.07320.44
5.6.50.0200.03320.38
5.6.40.0100.07020.46
5.6.30.0100.08320.57
5.6.20.0030.07720.32
5.6.10.0070.07720.43
5.6.00.0100.08320.42
5.5.380.0070.04020.52
5.5.370.0030.04020.39
5.5.360.0000.04320.41
5.5.350.0070.04020.36
5.5.340.0000.04320.84
5.5.330.0030.05020.95
5.5.320.0070.03720.82
5.5.310.0030.04320.90
5.5.300.0070.03320.91
5.5.290.0030.04320.94
5.5.280.0030.04320.83
5.5.270.0070.04020.85
5.5.260.0000.09720.86
5.5.250.0000.08720.66
5.5.240.0100.07720.24
5.5.230.0100.05320.26
5.5.220.0100.07720.29
5.5.210.0100.07720.13
5.5.200.0100.06720.17
5.5.190.0000.05720.15
5.5.180.0070.06020.26
5.5.160.0100.07320.29
5.5.150.0030.06720.14
5.5.140.0100.07320.02
5.5.130.0100.08020.23
5.5.120.0030.05720.28
5.5.110.0070.04020.01
5.5.100.0070.08020.16
5.5.90.0230.06720.12
5.5.80.0100.06020.09
5.5.70.0030.07320.02
5.5.60.0200.05319.95
5.5.50.0130.04320.03
5.5.40.0030.07719.97
5.5.30.0130.06720.17
5.5.20.0100.07020.07
5.5.10.0100.07020.05
5.5.00.0030.08020.06
5.4.450.0030.04019.42
5.4.440.0030.07019.17
5.4.430.0030.03319.27
5.4.420.0130.07319.19
5.4.410.0100.07319.41
5.4.400.0100.07319.14
5.4.390.0130.07018.90
5.4.380.0170.07019.14
5.4.370.0100.04318.94
5.4.360.0030.04019.09
5.4.350.0070.07019.04
5.4.340.0070.07719.18
5.4.320.0070.08019.03
5.4.310.0100.08019.09
5.4.300.0100.07019.03
5.4.290.0070.07319.20
5.4.280.0030.05018.87
5.4.270.0070.04318.86
5.4.260.0130.07319.04
5.4.250.0170.07018.84
5.4.240.0030.05718.96
5.4.230.0000.05019.00
5.4.220.0330.03719.20
5.4.210.0070.05318.84
5.4.200.0030.05019.04
5.4.190.0030.06719.24
5.4.180.0130.06719.18
5.4.170.0070.07719.03
5.4.160.0130.06718.85
5.4.150.0070.07319.02
5.4.140.0070.03716.38
5.4.130.0070.07716.37
5.4.120.0070.06316.42
5.4.110.0100.05316.36
5.4.100.0100.07016.47
5.4.90.0130.06316.36
5.4.80.0030.07016.49
5.4.70.0130.04716.36
5.4.60.0000.07316.42
5.4.50.0100.07716.29
5.4.40.0170.06316.42
5.4.30.0230.03016.53
5.4.20.0100.07016.53
5.4.10.0070.05016.32
5.4.00.0100.06015.82
5.3.290.0100.07014.78
5.3.280.0030.04314.59
5.3.270.0130.06314.70
5.3.260.0070.07014.75
5.3.250.0030.04714.74
5.3.240.0000.05014.64
5.3.230.0130.06714.56
5.3.220.0100.03314.62
5.3.210.0030.07714.63
5.3.200.0070.07014.65
5.3.190.0070.07714.72
5.3.180.0200.04014.68
5.3.170.0000.08014.66
5.3.160.0000.05714.66
5.3.150.0100.07714.63
5.3.140.0030.07314.65
5.3.130.0070.07014.64
5.3.120.0030.08314.53
5.3.110.0170.06714.58
5.3.100.0130.07014.09
5.3.90.0170.06314.11
5.3.80.0030.05314.05
5.3.70.0070.07314.06
5.3.60.0030.07714.02
5.3.50.0070.07713.88
5.3.40.0100.07313.99
5.3.30.0000.07713.96
5.3.20.0070.07313.64
5.3.10.0100.07013.70
5.3.00.0170.05713.81
5.2.170.0100.05711.18
5.2.160.0100.04011.29
5.2.150.0030.06011.31
5.2.140.0170.02711.07
5.2.130.0100.03311.12
5.2.120.0000.04311.14
5.2.110.0070.04011.16
5.2.100.0030.04311.13
5.2.90.0070.04711.26
5.2.80.0070.03311.21
5.2.70.0000.06311.24
5.2.60.0030.06311.07
5.2.50.0070.06011.07
5.2.40.0030.05711.09
5.2.30.0130.04711.03
5.2.20.0070.06011.13
5.2.10.0070.06010.88
5.2.00.0030.06310.66
5.1.60.0100.0509.88
5.1.50.0000.04310.11
5.1.40.0030.04310.10
5.1.30.0000.03310.51
5.1.20.0070.03710.39
5.1.10.0030.04710.10
5.1.00.0030.05710.17
5.0.50.0000.0478.47
5.0.40.0070.0278.54
5.0.30.0030.0638.11
5.0.20.0100.0308.12
5.0.10.0000.0278.28
5.0.00.0030.0608.26
4.4.90.0130.0207.32
4.4.80.0070.0337.32
4.4.70.0030.0377.32
4.4.60.0030.0307.32
4.4.50.0030.0377.32
4.4.40.0030.0437.32
4.4.30.0030.0237.32
4.4.20.0030.0377.32
4.4.10.0100.0177.32
4.4.00.0000.0537.32
4.3.110.0000.0237.32
4.3.100.0000.0207.32
4.3.90.0000.0277.32
4.3.80.0000.0537.32
4.3.70.0000.0377.32
4.3.60.0070.0237.32
4.3.50.0000.0407.32
4.3.40.0000.0537.32
4.3.30.0000.0377.32
4.3.20.0000.0377.32
4.3.10.0100.0177.32
4.3.00.0000.0307.32

preferences:
44.51 ms | 401 KiB | 5 Q