Skip to content

Instantly share code, notes, and snippets.

@morimori
Created November 1, 2011 07:29
Show Gist options
  • Save morimori/1330095 to your computer and use it in GitHub Desktop.
Save morimori/1330095 to your computer and use it in GitHub Desktop.
ruby Digest::* benchmark
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)
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
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)
@phigrofi
Copy link

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