php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79024 very slow hash('sha1', ...)
Submitted: 2019-12-24 00:11 UTC Modified: 2019-12-24 10:32 UTC
From: bugzilla77 at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: hash related
PHP Version: 7.4.1 OS: Windows 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
32 + 49 = ?
Subscribe to this entry?

 
 [2019-12-24 00:11 UTC] bugzilla77 at gmail dot com
Description:
------------
very slow hash('sha1', ...)

Test script:
---------------
<?php
 $i=2000000;

 $x=sha1(microtime(1).mt_rand());

 $time_a=microtime(true);
 for($z=0;$z<$i;$z++){
  $a=sha1($x);
 }
 $time_a=microtime(true)-$time_a;

 $time_b=microtime(true);
 for($z=0;$z<$i;$z++){
  $b=hash('sha1',$x);
 }
 $time_b=microtime(true)-$time_b;

 $time_c=microtime(true);
 for($z=0;$z<$i;$z++){
  $c=hash('sha1',$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.98706293106079 sec
<=0.98706293106079 sec
<=0.98706293106079 sec

Actual result:
--------------
0.98706293106079 sec
1.248526096344 sec
1.1808590888977 sec

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-24 10:32 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2019-12-24 10:32 UTC] cmb@php.net
Closing as duplicate of bug #79023, since the behavior has the
same root cause.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC