Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
@BookOfGreg

This comment has been minimized.

Copy link

BookOfGreg commented Oct 12, 2017

ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

Rehearsal ------------------------------------------
MD5      0.630000   0.000000   0.630000 (  0.641205)
SHA1     0.500000   0.000000   0.500000 (  0.498556)
SHA2     1.060000   0.010000   1.070000 (  1.068877)
SHA256   1.030000   0.000000   1.030000 (  1.031443)
--------------------------------- total: 3.230000sec

             user     system      total        real
MD5      0.660000   0.010000   0.670000 (  0.663826)
SHA1     0.520000   0.000000   0.520000 (  0.520652)
SHA2     1.090000   0.000000   1.090000 (  1.094845)
SHA256   1.030000   0.000000   1.030000 (  1.027715)

Ruby SHA1 became faster at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.