3v4l.org

run code in 300+ PHP versions simultaneously
<?php //bk2020 cc0 // SipHash-2-4 // Aumasson and Bernstein 2012, https://131002.net/siphash/ // https://github.com/jedisct1/libsodium/tree/master/src/libsodium/crypto_shorthash // https://github.com/php/php-src/tree/master/ext/sodium/libsodium.c#L472 function bytes_as_hex(&$str, $len=null) { if( !$len ) { $len = strlen($str); } // zero-based array index for unpack, kennwhite 2005: // https://www.php.net/manual/en/function.unpack.php#45188 $arrhead = array_merge( unpack('C*', substr($str,0,$len)) ); return array_reduce( $arrhead, function($a,$b) { return ($b>15) ? $a.dechex($b) : $a.'0'.dechex($b); }, '' ); } $SIPHASH = null; if( function_exists('\sodium_crypto_shorthash') ) { $SIPHASH = 'sodium_crypto_shorthash'; } else if( function_exists('\Sodium\crypto_shorthash') ) { $SIPHASH = '\Sodium\crypto_shorthash'; } else { die('Unable to test SipHash-2-4 using sodium_crypto_shorthash'); } $SIPKEY = '1234567890abcdef'; // 16-byte key for SipHash-2-4 echo '# ', $SIPHASH, PHP_EOL; // thanks to: https://3v4l.org/EsGSU // (note: bin2hex won't print leading zero on byte values <16) for ($i = 0; $i < 256; ++$i) { $msg = bin2hex( chr(($i & 0x3F) | 0x80) ); $aref = hrtime(); $hsh = $SIPHASH( $msg, $SIPKEY ); $anow = hrtime(); echo $i, "\t", bytes_as_hex($hsh,8), print_r($aref,true), print_r($anow,true), PHP_EOL; }

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.0160.01318.30
8.3.50.0040.01418.21
8.3.40.0110.00720.29
8.3.30.0160.00318.63
8.3.20.0060.00324.18
8.3.10.0030.00624.66
8.3.00.0070.00326.16
8.2.180.0090.01225.92
8.2.170.0080.01118.75
8.2.160.0150.00322.96
8.2.150.0060.00325.66
8.2.140.0060.00324.66
8.2.130.0090.00026.16
8.2.120.0060.00321.03
8.2.110.0040.00719.12
8.1.280.0120.00625.92
8.1.270.0080.00424.02
8.1.260.0070.01126.35
8.1.250.0040.00428.09
8.1.240.0040.00719.13
7.4.100.0160.01316.41
7.4.90.0140.02216.33
7.4.80.0210.01516.44
7.4.70.0260.00416.18
7.4.60.0170.02016.32
7.4.50.0220.02016.26
7.4.40.0100.01816.21
7.4.30.0150.01516.36
7.4.20.0240.00916.51
7.4.10.0240.01016.28
7.4.00.0130.01716.50
7.3.220.0170.01416.41
7.3.210.0140.01816.28
7.3.200.0210.01516.40
7.3.190.0030.03116.39
7.3.180.0120.02316.35
7.3.170.0180.01516.18
7.3.160.0210.00916.52
7.3.150.0190.01216.22
7.3.140.0170.01416.30
7.3.130.0140.01816.42
7.3.120.0210.01016.49
7.3.110.0230.00616.18
7.3.100.0120.01516.36
7.3.90.0170.01316.44
7.3.80.0170.01316.50
7.3.70.0140.01416.20
7.3.60.0090.01616.25
7.3.50.0140.01116.23
7.2.330.0110.01716.52
7.2.320.0140.00916.76
7.2.310.0130.01016.27
7.2.300.0130.00916.42
7.2.290.0100.01316.53
7.2.280.0160.00316.47
7.2.270.0190.00416.57
7.2.260.0200.00316.29
7.2.250.0070.01816.25
7.2.240.0160.00616.19
7.2.230.0080.01316.46
7.2.220.0100.01016.32
7.2.210.0080.01216.31
7.2.200.0110.00816.42
7.2.190.0120.00816.27

preferences:
42.76 ms | 401 KiB | 5 Q