Req #53213 [Fbk->Opn]: Adler32 algorithm is very slow

From: Date: Tue, 02 Nov 2010 03:05:55 +0000
Subject: Req #53213 [Fbk->Opn]: Adler32 algorithm is very slow
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155698@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53213&edit=1

 ID:                 53213
 Updated by:         aharvey@php.net
 Reported by:        zavasek at yandex dot ru
 Summary:            Adler32 algorithm is very slow
-Status:             Feedback
+Status:             Open
 Type:               Feature/Change Request
 Package:            hash related
 Operating System:   Any
 PHP Version:        5.3.3
 Block user comment: N



Previous Comments:
------------------------------------------------------------------------
[2010-10-31 20:45:28] pajoye@php.net

svn diff > mypatch.txt

and upload mypatch.txt here using the Add Patch link.

------------------------------------------------------------------------
[2010-10-31 20:40:47] zavasek at yandex dot ru

I've never used SVN and do not know how to create patches.

------------------------------------------------------------------------
[2010-10-31 19:14:48] pajoye@php.net

Can you provide a patch and attach it to this bug please ("Add a
patch")?

------------------------------------------------------------------------
[2010-10-31 18:22:17] zavasek at yandex dot ru

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 this bug report at http://bugs.php.net/bug.php?id=53213&edit=1


Thread (6 messages)

« previous php.bugs (#155698) next »