Skip to content

Instantly share code, notes, and snippets.

@stan
Forked from jseifer/password_benchmark.rb
Created May 7, 2010 08:59
Show Gist options
  • Save stan/393214 to your computer and use it in GitHub Desktop.
Save stan/393214 to your computer and use it in GitHub Desktop.
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