Created
May 6, 2012 02:29
-
-
Save metaskills/2607144 to your computer and use it in GitHub Desktop.
Benchmark Pusher Usage of Ruby HMAC vs OpenSSL
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'benchmark' | |
require 'hmac-sha2' | |
require 'openssl' | |
REPEAT = 10_000 | |
KEY = 'secretkey' | |
DATA = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' | |
DIGEST = OpenSSL::Digest::Digest.new('sha256') | |
Benchmark.bmbm do |results| | |
results.report('ruby-hmac') do | |
REPEAT.times do | |
HMAC::SHA256.hexdigest KEY, DATA | |
end | |
end | |
results.report('openssl/hmac') do | |
REPEAT.times do | |
OpenSSL::HMAC.hexdigest DIGEST, KEY, DATA | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Said results.