Created
October 28, 2016 15:04
-
-
Save diegoeche/365cb1187d86b323d75f60a47357b22b to your computer and use it in GitHub Desktop.
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/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