Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98711 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90019 invoked from network); 1 Apr 2017 03:13:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Apr 2017 03:13:42 -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:44088] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 77/C0-19101-2EA1FD85 for ; Fri, 31 Mar 2017 22:13:40 -0500 Received: (qmail 20719 invoked by uid 89); 1 Apr 2017 03:13:35 -0000 Received: from unknown (HELO mail-qt0-f180.google.com) (yohgaki@ohgaki.net@209.85.216.180) by 0 with ESMTPA; 1 Apr 2017 03:13:35 -0000 Received: by mail-qt0-f180.google.com with SMTP id i34so79812176qtc.0 for ; Fri, 31 Mar 2017 20:13:34 -0700 (PDT) X-Gm-Message-State: AFeK/H1vn10fCT41tkqfx+z2JZL1gVAjQYL38DSVym48mc3N3fzdvDL9HC8mY8MffmYLlfXBmDL9BgMIbbTb7Q== X-Received: by 10.237.53.48 with SMTP id a45mr5882176qte.286.1491016408527; Fri, 31 Mar 2017 20:13:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.19.232 with HTTP; Fri, 31 Mar 2017 20:12:48 -0700 (PDT) Date: Sat, 1 Apr 2017 12:12:48 +0900 X-Gmail-Original-Message-ID: Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c000ae62d3a7054c124fd2 Subject: SHA3 is very slow From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c000ae62d3a7054c124fd2 Content-Type: text/plain; charset=UTF-8 Hi all, I noticed that our SHA-3 is inefficient. === Ruby SHA3-256 === [yohgaki@dev ~]$ cat t2.rb #!/usr/bin/env ruby require 'digest/sha2' $i = 1000000 until $i do Digest::SHA3.hexdigest("abcdedf", 256) $i -= 1 end [yohgaki@dev ~]$ time ruby t2.rb real 0m0.438s user 0m0.216s sys 0m0.222s [yohgaki@dev ~]$ time ruby t2.rb real 0m0.429s user 0m0.228s sys 0m0.202s [yohgaki@dev ~]$ === Ruby SHA2-256 === [yohgaki@dev ~]$ cat t.rb #!/usr/bin/env ruby require 'digest/sha2' $i = 1000000 until $i do Digest::SHA2.hexdigest("abcdedf", 256) $i -= 1 end [yohgaki@dev ~]$ time ruby t.rb real 0m0.431s user 0m0.228s sys 0m0.205s [yohgaki@dev ~]$ time ruby t.rb real 0m0.409s user 0m0.208s sys 0m0.203s === PHP master SHA3-256 === [yohgaki@dev PHP-master]$ time ./php-bin -r '$s = microtime(true); for ($i = 0; $i < 1000000; $i++) { hash("sha3-256", "abcdefg"); } var_dump(microtime(true) - $s); ' float(2.7503371238708) real 0m2.764s user 0m2.755s sys 0m0.005s [yohgaki@dev PHP-master]$ time ./php-bin -r '$s = microtime(true); for ($i = 0; $i < 1000000; $i++) { hash("sha3-256", "abcdefg"); } var_dump(microtime(true) - $s); ' float(2.8106999397278) real 0m2.831s user 0m2.823s sys 0m0.003s === PHP master SHA2-256 === [yohgaki@dev PHP-master]$ time ./php-bin -r '$s = microtime(true); for ($i = 0; $i < 1000000; $i++) { hash("sha256", "abcdefg"); } var_dump(microtime(true) - $s); ' float(0.48856687545776) real 0m0.502s user 0m0.499s sys 0m0.002s [yohgaki@dev PHP-master]$ time ./php-bin -r '$s = microtime(true); for ($i = 0; $i < 1000000; $i++) { hash("sha256", "abcdefg"); } var_dump(microtime(true) - $s); ' float(0.48898410797119) real 0m0.505s user 0m0.499s sys 0m0.005s As you can see, PHP's SHA3 is about 6 times slower. According to DJB's benchmark, it seems SHA-3 could be as fast as SHA-2. https://bench.cr.yp.to/results-sha3.html Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c000ae62d3a7054c124fd2--