diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-12-07 21:00:16 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-12-07 21:00:16 -0800 |
| commit | 26235f94f87b01058cc06e69902f7fb30bffb22f (patch) | |
| tree | f33aa295569104cf93caef3747efe11f2307c447 /tools/finditer/finditer.go | |
| parent | 98aa0f09acc956d72bfca6d4cdf22cbd40b87d1e (diff) | |
| download | roseh.moe-26235f94f87b01058cc06e69902f7fb30bffb22f.tar.zst | |
Update finditer
Diffstat (limited to 'tools/finditer/finditer.go')
| -rw-r--r-- | tools/finditer/finditer.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/tools/finditer/finditer.go b/tools/finditer/finditer.go index 99c17ee..a56c7fa 100644 --- a/tools/finditer/finditer.go +++ b/tools/finditer/finditer.go @@ -20,23 +20,23 @@ func mustHex(s string) []byte { var salt = mustHex("34539b5dd2591415") -func benchmarkHashIter(iter int) time.Duration { +var iter int + +func BenchmarkHashIter(b *testing.B) { const password = "wavy upend 4z jk linda k zing four atop pi" - return time.Duration(testing.Benchmark(func(b *testing.B) { - for b.Loop() { - pwhash.HashIter(password, salt, iter) - } - }).NsPerOp()) + for b.Loop() { + pwhash.HashIter(password, salt, iter) + } } func main() { const targetTime = 5 * time.Second - iter := 8192 - for ; benchmarkHashIter(iter) < targetTime; iter *= 2 { + for iter = 8192; time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) < targetTime; iter *= 2 { } lo := iter / 2 hi := iter fmt.Println(lo + sort.Search(hi-lo, func(n int) bool { - return benchmarkHashIter(lo+n) > targetTime + iter = lo + n + return time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) > targetTime })) } |
