Skip to content

Instantly share code, notes, and snippets.

@greyblake
Created February 19, 2018 10:22
Show Gist options
  • Save greyblake/715c861d4180c5a15c10fbe458cf48ae to your computer and use it in GitHub Desktop.
Save greyblake/715c861d4180c5a15c10fbe458cf48ae to your computer and use it in GitHub Desktop.
require "securerandom"
require "digest/md5"
require "benchmark"
data1 = SecureRandom.random_bytes(5 * 1024 * 1024)
data2 = data1.dup
N = 500
Benchmark.bm do |x|
x.report("md5") do
N.times do
Digest::MD5.hexdigest(data1) == Digest::MD5.hexdigest(data2)
end
end
x.report("direct") do |x|
N.times do
data1 == data2
end
end
end
# Output
# user system total real
# md5 7.376000 0.000000 7.376000 ( 7.376198)
# direct 0.000000 0.000000 0.000000 ( 0.000025)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment