generateTestData generates the test data and warm up the cache if required.
(b *testing.B, cache Cache, warmCache bool, key string, numPasswords int)
| 384 | |
| 385 | // generateTestData generates the test data and warm up the cache if required. |
| 386 | func generateTestData(b *testing.B, cache Cache, warmCache bool, key string, numPasswords int) []hashAndPassword { |
| 387 | hashAndPasswords := make([]hashAndPassword, numPasswords) |
| 388 | for i := 0; i < numPasswords; i++ { |
| 389 | password := []byte(fmt.Sprintf("%s%d", key, i)) |
| 390 | hashAndPassword := hashAndPassword{ |
| 391 | hash: bcryptHash(b, password), |
| 392 | password: password, |
| 393 | } |
| 394 | hashAndPasswords[i] = hashAndPassword |
| 395 | if warmCache { |
| 396 | key := authKey(hashAndPassword.hash, hashAndPassword.password) |
| 397 | cache.Put(key) |
| 398 | } |
| 399 | } |
| 400 | return hashAndPasswords |
| 401 | } |
| 402 | |
| 403 | func BenchmarkCompareHashAndPassword100PercentCacheHit(b *testing.B) { |
| 404 | const maxCacheSize = 100 |
no test coverage detected