How do I make has_secure_password (bcrypt hashes) faster in Rails
-
12-12-2019 - |
Question
Another self-answer for posterity. :)
Creating models with has_secure_password
(which uses a bcrypt hash) is really slow. User.create!
takes about 0.3 seconds.
This slows down my test suite. How do I improve performance?
Solution
Semyon Perepelitsa graciously posted the following snippet for test_helper/spec_helper:
require "bcrypt"
silence_warnings do
BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
end
This weakens the hash function, making hash calculation near-instantaneous in test mode - just what we want!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow