|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73277 crc32() not using CPU capabilities
Submitted: 2016-10-09 16:45 UTC Modified: 2021-03-03 13:37 UTC
From: spam2 at rhsoft dot net Assigned:
Status: Open Package: Performance problem
PHP Version: 7.0.11 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: spam2 at rhsoft dot net
New email:
PHP Version: OS:


 [2016-10-09 16:45 UTC] spam2 at rhsoft dot net
for short messages crc32 seems to be the fastest way but for long messages like a whole page content for a ETAG-HTTP-Header it's the slowest

md5:   0.48954606056213
sha1:  0.57872104644775
crc32: 0.64182901382446

that should not be the case on modern Intel CPUs like SnadyBrdige or newer which support a accelerated instruction

Test script:
$test_content = file_get_contents('', true);

echo '<strong>md5: </strong>' . md5($test_content) . MY_LE;
 $rw = md5($test_content);
echo $profiler->get() . '<br /><br />' .  MY_LE;

echo '<strong>sha1: </strong>' . sha1($test_content) . MY_LE;
 $rw = sha1($test_content);
echo $profiler->get() . '<br /><br />' .  MY_LE;

echo '<strong>crc32: </strong>' . abs(crc32($test_content)) . MY_LE;
 $rw = crc32($test_content);
echo $profiler->get() . '<br /><br />' .  MY_LE;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-03 13:07 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-03-03 13:07 UTC]
The crc32 implementation has been improved since PHP 7.0.11.  Is
it good for you now?
 [2021-03-03 13:15 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
md4:         0.18111
md5:         0.28866
sha1:        0.40015
crc32:       0.47416

still the slowest
 [2021-03-03 13:37 UTC]
-Status: Feedback +Status: Open -Assigned To: cmb +Assigned To:
 [2021-03-03 13:37 UTC]
Thanks for checking!  I presume this has been measures with PHP 8.0?
 [2021-03-03 13:44 UTC] rtrtrtrtrt at dfdfdfdf dot dfd

i gave up PHP8 a while ago since it don't build with PGO here (segfault in mod_php as soon as it's loaded) and the nonsense of deprecate zip-functions without 1:1 replacement as well as don't make it easier either in an environment treating notices/warnings as fatal errors
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 21:01:28 2024 UTC