Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98730 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66999 invoked from network); 5 Apr 2017 02:32:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Apr 2017 02:32:34 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ohgaki.net designates 180.42.98.130 as permitted sender) X-PHP-List-Original-Sender: yohgaki@ohgaki.net X-Host-Fingerprint: 180.42.98.130 ns1.es-i.jp Received: from [180.42.98.130] ([180.42.98.130:59778] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 17/15-19282-F3754E85 for ; Tue, 04 Apr 2017 22:32:33 -0400 Received: (qmail 124941 invoked by uid 89); 5 Apr 2017 02:32:28 -0000 Received: from unknown (HELO mail-qk0-f171.google.com) (yohgaki@ohgaki.net@209.85.220.171) by 0 with ESMTPA; 5 Apr 2017 02:32:28 -0000 Received: by mail-qk0-f171.google.com with SMTP id h67so267629qke.0 for ; Tue, 04 Apr 2017 19:32:27 -0700 (PDT) X-Gm-Message-State: AFeK/H2tYG/U01lQwvJ/VU1suC7dhsLp0lrCK8/5vfOloOOk4h2alC4gCq7nV41gUDtHb8Rb4YmrN7sv1uBnKQ== X-Received: by 10.55.204.157 with SMTP id n29mr18165030qkl.73.1491359541058; Tue, 04 Apr 2017 19:32:21 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.19.232 with HTTP; Tue, 4 Apr 2017 19:31:40 -0700 (PDT) In-Reply-To: <45858E8B-05A8-4EAB-97B0-A17C3D8BDD96@cschneid.com> References: <45858E8B-05A8-4EAB-97B0-A17C3D8BDD96@cschneid.com> Date: Wed, 5 Apr 2017 11:31:40 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Christian Schneider Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a1146d052ad87c2054c62336c Subject: Re: [PHP-DEV] SHA3 is very slow From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a1146d052ad87c2054c62336c Content-Type: text/plain; charset=UTF-8 Hi Christian, On Mon, Apr 3, 2017 at 8:44 PM, Christian Schneider wrote: > Two things I noticed: > 1) As far as I understand Ruby (and as far as I tested it) this does not > execute the function at all. You probably mean something like > while $i > 0 do > Oops, forgot to add "== 0" [yohgaki@dev ~]$ cat t.rb #!/usr/bin/env ruby require 'digest/sha2' $i = 1000000 until $i == 0 do Digest::SHA2.hexdigest("abcdedf", 256) $i -= 1 end [yohgaki@dev ~]$ time ruby t.rb real 0m1.790s user 0m1.596s sys 0m0.194s [yohgaki@dev ~]$ cat t2.rb #!/usr/bin/env ruby require 'digest/sha2' $i = 1000000 until $i == 0 do Digest::SHA3.hexdigest("abcdedf", 256) $i -= 1 end [yohgaki@dev ~]$ time ruby t2.rb real 0m2.594s user 0m2.429s sys 0m0.165s PHP's sha3 seems slower than it could be. I knew DJB benchmark before the tests, so I was sloppy. > 2) For some reason the Ruby implementation yields different results, I > didn't track down why. > - hash("sha3-256", "abc"); => 3a985da74fe225b2045c172d6bd390 > bd855f086e3e9d525b46bfe24511431532 > which matches the test vector at http://www.di-mgt.com.au/sha_t > estvectors.html > - Digest::SHA3.hexdigest("abc", 256) => > 4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45 > > For whatever reason this is, it means that you can't really compare those > two functions. > Nice finding. https://github.com/phusion/digest-sha3-ruby seems a little old. It may not implement final version. Whichever is wrong, we may be better look into this. Anyway, it seems someone is better to try to improve SHA3 performance. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a1146d052ad87c2054c62336c--