Skip to content

Instantly share code, notes, and snippets.

@diegoeche
Created October 28, 2016 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegoeche/365cb1187d86b323d75f60a47357b22b to your computer and use it in GitHub Desktop.
Save diegoeche/365cb1187d86b323d75f60a47357b22b to your computer and use it in GitHub Desktop.
require "digest/md5"
require "openssl"
require "securerandom"
require 'benchmark'
require "base64"
SIZE = 1000
def create_test
ret = []
SIZE.times do
ret << SecureRandom.random_bytes(1000000)
end
ret
end
def test_digest(x)
Digest::MD5.hexdigest(x)
end
def test_openssl(x)
digest = OpenSSL::Digest::MD5.new
digest << x
digest.hexdigest
end
test = nil
puts "Creating Test Data"
puts Benchmark.measure {
test = create_test
}
puts "Testing digest/md5"
puts Benchmark.measure {
test.map { |x| test_digest(x) }
}
puts "Testing openssl"
puts Benchmark.measure {
test.map { |x| test_openssl(x) }
}
# Creating Test Data
# 27.430000 0.440000 27.870000 ( 28.132352)
# Testing digest/md5
# 1.570000 0.000000 1.570000 ( 1.570979)
# Testing openssl
# 1.540000 0.010000 1.550000 ( 1.569205)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment