Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98740 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49313 invoked from network); 6 Apr 2017 00:32:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Apr 2017 00:32:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; 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:36790] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/35-08240-AAC85E85 for ; Wed, 05 Apr 2017 20:32:44 -0400 Received: (qmail 72542 invoked by uid 89); 6 Apr 2017 00:32:39 -0000 Received: from unknown (HELO mail-qk0-f175.google.com) (yohgaki@ohgaki.net@209.85.220.175) by 0 with ESMTPA; 6 Apr 2017 00:32:39 -0000 Received: by mail-qk0-f175.google.com with SMTP id f133so8200973qke.2 for ; Wed, 05 Apr 2017 17:32:38 -0700 (PDT) X-Gm-Message-State: AFeK/H2SEcSL6tjqlEualMO0USQIouZ/egGODgmHYyQTZAjGxQZV2lGTRfifBWRs6him+2L1ThYd0F+Bp6SWAg== X-Received: by 10.55.65.81 with SMTP id o78mr29018228qka.82.1491438752228; Wed, 05 Apr 2017 17:32:32 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.19.232 with HTTP; Wed, 5 Apr 2017 17:31:51 -0700 (PDT) In-Reply-To: <0B2BAD15-48AB-4095-A675-C2763ED2D91D@cschneid.com> References: <45858E8B-05A8-4EAB-97B0-A17C3D8BDD96@cschneid.com> <0B2BAD15-48AB-4095-A675-C2763ED2D91D@cschneid.com> Date: Thu, 6 Apr 2017 09:31:51 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Christian Schneider Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a114ac54e07f22f054c74a59b Subject: Re: [PHP-DEV] SHA3 is very slow From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a114ac54e07f22f054c74a59b Content-Type: text/plain; charset=UTF-8 Hi Christian, On Thu, Apr 6, 2017 at 12:45 AM, Christian Schneider wrote: > > I created a pull request at https://github.com/php/php-src/pull/2453 for > a version using the KeccakCodePackage version from > https://github.com/gvanas/KeccakCodePackage which yields ~30 times faster > results for a simple test. > Nice work!! SHA3 is now faster than SHA2. ==== Small String ==== [yohgaki@dev php-src]$ time ./php-bin -r '$s = microtime(true); for ($i = 0; $i < 1000000; $i++) { hash("sha256", "abcdefg"); } var_dump(microtime(true) - $s); ' float(0.46163821220398) real 0m0.557s user 0m0.471s sys 0m0.086s [yohgaki@dev php-src]$ time ./php-bin -r '$s = microtime(true); for ($i = 0; $i < 1000000; $i++) { hash("sha3-256", "abcdefg"); } var_dump(microtime(true) - $s); ' float(0.57230806350708) real 0m0.585s user 0m0.579s sys 0m0.006s ==== Large String ==== [yohgaki@dev php-src]$ time ./php-bin -r '$s = microtime(true);$v = str_repeat("a", 9999999); for ($i = 0; $i < 100; $i++) { hash("sha256", $v); } var_dump(microtime(true) - $s); ' float(4.6689560413361) real 0m4.691s user 0m4.675s sys 0m0.009s [yohgaki@dev php-src]$ time ./php-bin -r '$s = microtime(true);$v = str_repeat("a", 9999999); for ($i = 0; $i < 100; $i++) { hash("sha3-256", $v); } var_dump(microtime(true) - $s); ' float(2.9090809822083) real 0m2.928s user 0m2.919s sys 0m0.005s > I don't know whether the PHP maintainers prefer to keep the (very short) > inline reference implementation which is slow or whether the optimised > version from KeccakCodePackage with around a dozen files would be > acceptable. > > I put the (part which is used from the) KeccakCodePackage code (without > modifications!) in a separate directory under ext/hash/sha3 and I also > implemented switching between a 64bit and a 32bit version. Don't know if > this is necessary and following all the guidelines. > > Oh, I also only superficially scanned > https://github.com/gvanas/KeccakCodePackage#under-which- > license-is-the-kcp-distributed > but it looked like it should be ok. Not an expert on this though ;-) > It's fine for me. I'll wait few weeks for more comments. If not, I'll merge your PR to master. I don't think we really need to merge it to released version. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a114ac54e07f22f054c74a59b--