Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require 'rubygems'
require 'benchmark'
require 'bcrypt'
REPITITIONS = 50
passwords = %w(password)
passwords.each do |password|
puts "Password to hash: #{password}"
Benchmark.bm(12) do |x|
x.report("MD5") { REPITITIONS.times { Digest::MD5.hexdigest(password)} }
x.report("SHA1") { REPITITIONS.times { Digest::SHA1.hexdigest(password) } }
x.report("SHA256") { REPITITIONS.times { Digest::SHA256.hexdigest(password)} }
x.report("bcrypt (3)") { REPITITIONS.times { BCrypt::Password.create(password, :cost => 3)} }
x.report("bcrypt (10)") { REPITITIONS.times { BCrypt::Password.create(password, :cost => 10)} }
end
puts "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment