Created
November 1, 2011 07:29
-
-
Save morimori/1330095 to your computer and use it in GitHub Desktop.
ruby Digest::* benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux] | |
Rehearsal ------------------------------------------ | |
MD5 1.010000 0.000000 1.010000 ( 1.026340) | |
SHA1 1.710000 0.000000 1.710000 ( 1.724464) | |
SHA2 3.780000 0.000000 3.780000 ( 3.824757) | |
SHA256 3.460000 0.010000 3.470000 ( 3.498111) | |
--------------------------------- total: 9.970000sec | |
user system total real | |
MD5 1.020000 0.000000 1.020000 ( 1.025751) | |
SHA1 1.700000 0.000000 1.700000 ( 1.723694) | |
SHA2 3.770000 0.000000 3.770000 ( 3.816861) | |
SHA256 3.450000 0.010000 3.460000 ( 3.490535) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest/sha1' | |
require 'digest/sha2' | |
require 'benchmark' | |
SRC = File.read '/dev/urandom', 4096 | |
Benchmark.bmbm do |bm| | |
bm.report('MD5') { 100000.times{ Digest::MD5.hexdigest SRC } } | |
bm.report('SHA1') { 100000.times{ Digest::SHA1.hexdigest SRC } } | |
bm.report('SHA2') { 100000.times{ Digest::SHA2.hexdigest SRC } } | |
bm.report('SHA256') { 100000.times{ Digest::SHA256.hexdigest SRC } } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03 | |
Rehearsal ------------------------------------------ | |
MD5 1.200000 0.000000 1.200000 ( 1.215786) | |
SHA1 1.900000 0.000000 1.900000 ( 1.923869) | |
SHA2 4.240000 0.000000 4.240000 ( 4.280306) | |
SHA256 3.640000 0.000000 3.640000 ( 3.675077) | |
-------------------------------- total: 10.980000sec | |
user system total real | |
MD5 1.200000 0.000000 1.200000 ( 1.213259) | |
SHA1 1.910000 0.000000 1.910000 ( 1.929293) | |
SHA2 4.240000 0.010000 4.250000 ( 4.289109) | |
SHA256 3.640000 0.000000 3.640000 ( 3.668232) |
SHA1 is still pushing ahead.
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin19]
Rehearsal ------------------------------------------
MD5 0.679635 0.001569 0.681204 ( 0.682606)
SHA1 0.353058 0.000833 0.353891 ( 0.354815)
SHA2 0.494869 0.001247 0.496116 ( 0.497209)
SHA256 0.438576 0.001491 0.440067 ( 0.442002)
--------------------------------- total: 1.971278sec
user system total real
MD5 0.689410 0.001597 0.691007 ( 0.692521)
SHA1 0.351183 0.000932 0.352115 ( 0.352880)
SHA2 0.498587 0.002104 0.500691 ( 0.502838)
SHA256 0.434150 0.001679 0.435829 ( 0.437912)
Any idea why Ruby 3.x is much slower than Ruby 2.x with Digest performances?
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
Rehearsal ------------------------------------------
MD5 0.574656 0.000119 0.574775 ( 0.574811)
SHA1 0.261374 0.000011 0.261385 ( 0.261393)
SHA2 0.336301 0.000003 0.336304 ( 0.336328)
SHA256 0.281675 0.000000 0.281675 ( 0.281701)
--------------------------------- total: 1.454139sec
user system total real
MD5 0.571611 0.000000 0.571611 ( 0.571662)
SHA1 0.262690 0.000000 0.262690 ( 0.262703)
SHA2 0.336247 0.000001 0.336248 ( 0.336277)
SHA256 0.280140 0.000000 0.280140 ( 0.280164)
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
Rehearsal ------------------------------------------
MD5 0.599872 0.000192 0.600064 ( 0.600097)
SHA1 0.572730 0.000011 0.572741 ( 0.572760)
SHA2 1.567906 0.000001 1.567907 ( 1.567991)
SHA256 1.519071 0.000000 1.519071 ( 1.519210)
--------------------------------- total: 4.259783sec
user system total real
MD5 0.598482 0.000000 0.598482 ( 0.598519)
SHA1 0.573576 0.000000 0.573576 ( 0.573655)
SHA2 1.560271 0.000000 1.560271 ( 1.560460)
SHA256 1.519918 0.000000 1.519918 ( 1.520137)
On a debian system with ruby 3.2.0 Digest::MD5
and OpenSSL::Digest::MD5
have very different results for me.
On my M1 Mac they are mostly the same.
require 'benchmark'
require 'openssl'
require 'digest'
SRC = File.read '/dev/urandom', 4096
Benchmark.bmbm do |bm|
bm.report('MD5') { 100000.times{ Digest::MD5.hexdigest(SRC) } }
bm.report('MD5 OpenSSL') { 100000.times{ OpenSSL::Digest::MD5.new.hexdigest(SRC) } }
end
user system total real
MD5 2.649720 0.000000 2.649720 ( 2.649962)
MD5 OpenSSL 1.030964 0.000000 1.030964 ( 1.031064)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
Ruby SHA1 became faster at some point.