Skip to content

Instantly share code, notes, and snippets.

@jseifer
Created March 21, 2010 15:01
Show Gist options
  • Save jseifer/339346 to your computer and use it in GitHub Desktop.
Save jseifer/339346 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