Req #53213 [NEW]: Adler32 algorithm is very slow

From: Date: Sun, 31 Oct 2010 17:22:17 +0000
Subject: Req #53213 [NEW]: Adler32 algorithm is very slow
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155656@lists.php.net to get a copy of this message
From: Operating system: Any PHP version: 5.3.3 Package: hash related Bug Type: Feature/Change Request Bug description:Adler32 algorithm is very slow Description: ------------ Now adler32 algorithm for each byte uses two operations " % 65521". It is very slow. I propose to change the function PHP_ADLER32Update in the file hash_adler32.c { php_hash_uint32 i, s[2]; s[0] = context->state & 0xffff; s[1] = (context->state >> 16) & 0xffff; for (i = 0; i < len; ++i) { s[0] += input[i]; s[1] += s[0]; if (s[1]>0x7fffffff) { s[0] = s[0] % 65521; s[1] = s[1] % 65521; } } s[0] = s[0] % 65521; s[1] = s[1] % 65521; context->state = s[0] + (s[1] << 16); } Test script: --------------- <?php $t = microtime(true); echo hash_file('adler32','/home/user/testfile')."\n"; // I used testfile size 400 MB with random content echo sprintf('%0.3d',(microtime(true)-$t)*1000)." ms\n\n"; ?> Actual result: -------------- PHP 5.3.3 showed: 85ffb2c5 2174 ms After modification the file: 85ffb2c5 664 ms Speed was higher than about 3 times -- Edit bug report at http://bugs.php.net/bug.php?id=53213&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53213&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53213&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53213&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53213&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53213&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53213&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53213&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53213&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53213&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53213&r=support Expected behavior: http://bugs.php.net/fix.php?id=53213&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53213&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53213&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53213&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53213&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53213&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53213&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53213&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53213&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53213&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53213&r=mysqlcfg

« previous php.bugs (#155656) next »