Skip to content

Instantly share code, notes, and snippets.

@triangletodd
Created March 15, 2017 20:12
Show Gist options
  • Select an option

  • Save triangletodd/64db273ec2061ea23834c010079121b2 to your computer and use it in GitHub Desktop.

Select an option

Save triangletodd/64db273ec2061ea23834c010079121b2 to your computer and use it in GitHub Desktop.
Benchmarking BCrypt
require 'benchmark'
require 'bcrypt'
(5..15).to_a.each do |i|
bm = Benchmark.measure { BCrypt::Password.create('I have a hairy cat', cost: i) }
puts "cost: #{i} \t #{bm}"
end
#=> cost: 5 0.010000 0.000000 0.010000 ( 0.001988)
#=> cost: 6 0.000000 0.000000 0.000000 ( 0.004081)
#=> cost: 7 0.010000 0.000000 0.010000 ( 0.008516)
#=> cost: 8 0.010000 0.000000 0.010000 ( 0.015666)
#=> cost: 9 0.030000 0.010000 0.040000 ( 0.031448)
#=> cost: 10 0.060000 0.000000 0.060000 ( 0.062378)
#=> cost: 11 0.130000 0.000000 0.130000 ( 0.124678)
#=> cost: 12 0.230000 0.000000 0.230000 ( 0.240915)
#=> cost: 13 0.480000 0.000000 0.480000 ( 0.483705)
#=> cost: 14 0.960000 0.010000 0.970000 ( 0.966589)
#=> cost: 15 1.900000 0.000000 1.900000 ( 1.925419)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment