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 yohg...@ohgaki.net