Bug #79023 [Opn]: very slow hash('crc32b', ...)

From: Date: Tue, 24 Dec 2019 10:30:54 +0000
Subject: Bug #79023 [Opn]: very slow hash('crc32b', ...)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224513@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79023&edit=1 ID: 79023 Updated by: cmb@php.net Reported by: bugzilla77 at gmail dot com Summary: very slow hash('crc32b', ...) Status: Open Type: Bug Package: hash related Operating System: Windows 10 PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: Firstly, crc32($x) doesn't call hash('crc32b', $x), so the assumption that the latter should be equally fast as the former (or even faster) is wrong. Actually, these functions share only the actual hashing primitives. Since hash() has to first map the given string to the desired algorithm, and uses function pointers subsequently, it is supposed to be somewhat slower. However, hash() still uses classic ZPP, while crc32() uses the newer fast ZPP macros, what causes an additional performance penalty. Basically, the same applies to sha1() and md5(). Previous Comments: ------------------------------------------------------------------------ [2019-12-24 00:07:44] bugzilla77 at gmail dot com Description: ------------ very slow hash('crc32b', ...) Test script: --------------- <?php $i=2000000; $x=sha1(microtime(1).mt_rand()); $time_a=microtime(true); for($z=0;$z<$i;$z++){ $a=crc32($x); } $time_a=microtime(true)-$time_a; $time_b=microtime(true); for($z=0;$z<$i;$z++){ $b=hash('crc32b',$x); } $time_b=microtime(true)-$time_b; $time_c=microtime(true); for($z=0;$z<$i;$z++){ $c=hash('crc32b',$x,true); } $time_c=microtime(true)-$time_c; print($time_a.' sec'); print('<br/>'); print($time_b.' sec'); print('<br/>'); print($time_c.' sec'); ?> Expected result: ---------------- 0.34135699272156 sec <=0.34135699272156 sec <=0.34135699272156 sec Actual result: -------------- 0.34135699272156 sec 0.77139401435852 sec 0.80676794052124 sec ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79023&edit=1

« previous php.bugs (#224513) next »