Skip to content

Conversation

@ashwin47
Copy link
Contributor

@ashwin47 ashwin47 commented Jan 2, 2026

Set BCrypt::Engine.cost to MIN_COST (4) in test environment to speed up password hashing operations

Why

BCrypt's default cost factor (12) is designed for production security, where slow hashing protects against brute-force attacks. In tests, we're validating logic—not defending against attackers—so we can safely use the minimum cost without compromising test validity.

Benchmark Results

Branch Run 1 Run 2 Run 3 Average
main (before) 11.0s 10.0s 9.0s 10.0s
This PR (after) 4.0s 3.0s 4.0s 3.7s

Result: ~63% faster test suite execution

Details

BCrypt Cost Benchmark Comparison
Date: Fri Jan 2 16:30:17 IST 2026

BEFORE (without BCrypt optimization) (main)

→ Run 1: 11.0s - 259 runs, 742 assertions, 0 failures, 0 errors, 0 skips
→ Run 2: 10.0s - 259 runs, 742 assertions, 0 failures, 0 errors, 0 skips
→ Run 3: 9.0s - 259 runs, 742 assertions, 0 failures, 0 errors, 0 skips

AFTER (with BCrypt optimization) (reduce-bcrypt-cost-in-tests)

→ Run 1: 4.0s - 259 runs, 742 assertions, 0 failures, 0 errors, 0 skips
→ Run 2: 3.0s - 259 runs, 742 assertions, 0 failures, 0 errors, 0 skips
→ Run 3: 4.0s - 259 runs, 742 assertions, 0 failures, 0 errors, 0 skips

@ashwin47 ashwin47 closed this Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant