Skip to content

Instantly share code, notes, and snippets.

@bararchy
Last active October 26, 2015 11:07
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 bararchy/2662376a0a0858362f61 to your computer and use it in GitHub Desktop.
Save bararchy/2662376a0a0858362f61 to your computer and use it in GitHub Desktop.
Benchmarking Hash
require 'openssl'
require 'benchmark'
class Testing_Hash
def initialize(a_message, integer)
@message = a_message
@integer = integer
end
def md5_tester
@integer.times do
Digest::MD5.hexdigest @message
end
end
def sha256_tester
@integer.times do
Digest::SHA256.hexdigest @message
end
end
def hmac_tester
@integer.times do
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), 'key', @message)
end
end
def benchmark_hash
Benchmark.bmbm do |x|
x.report('md5') {md5_tester}
x.report('sha256') {sha256_tester}
x.report('hmac_tester') {hmac_tester}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment