|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-10-31 18:22 UTC] 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
Patchespatch.txt (last revision 2010-11-01 18:30 UTC by zavasek at yandex dot ru)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
Can you provide a patch and attach it to this bug please ("Add a patch")?