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
 [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

Pull Requests

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 Dec 26 13:01:30 2024 UTC