MCPcopy Index your code
hub / github.com/bcrypt-ruby/bcrypt-ruby / calibrate

Method calibrate

lib/bcrypt/engine.rb:119–126  ·  view source on GitHub ↗

Returns the cost factor which will result in computation times less than +upper_time_limit_in_ms+. Example: BCrypt::Engine.calibrate(200) #=> 10 BCrypt::Engine.calibrate(1000) #=> 12 # should take less than 200ms BCrypt::Password.create("woo", :cost => 10) # should take less than 1000ms BCrypt::Password.create("woo", :cost => 12)

(upper_time_limit_in_ms)

Source from the content-addressed store, hash-verified

117 # # should take less than 1000ms
118 # BCrypt::Password.create("woo", :cost => 12)
119 def self.calibrate(upper_time_limit_in_ms)
120 (BCrypt::Engine::MIN_COST..BCrypt::Engine::MAX_COST-1).each do |i|
121 start_time = Time.now
122 Password.create("testing testing", :cost => i+1)
123 end_time = Time.now - start_time
124 return i if end_time * 1_000 > upper_time_limit_in_ms
125 end
126 end
127
128 # Autodetects the cost from the salt string.
129 def self.autodetect_cost(salt)

Callers 1

engine_spec.rbFile · 0.80

Calls 1

createMethod · 0.80

Tested by

no test coverage detected