diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-10-05 21:58:44 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-10-05 21:58:44 -0700 |
| commit | bcbb629db87b6bc0e9a7880ec4ee1c90d284a6c7 (patch) | |
| tree | 7372c59802fb589f798a9e849d621dac158dc04b /tools/finditers/finditers.go | |
| parent | 83d80b0672be886e7c6ccfad60949dbddb1b4173 (diff) | |
| download | roseh.moe-bcbb629db87b6bc0e9a7880ec4ee1c90d284a6c7.tar.zst | |
Bring back the notepad
Diffstat (limited to 'tools/finditers/finditers.go')
| -rw-r--r-- | tools/finditers/finditers.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/finditers/finditers.go b/tools/finditers/finditers.go new file mode 100644 index 0000000..31a7e33 --- /dev/null +++ b/tools/finditers/finditers.go @@ -0,0 +1,42 @@ +package main + +import ( + "encoding/hex" + "fmt" + "sort" + "testing" + "time" + + "gitlab.com/rhogenson/roseh.moe/internal/pwhash" +) + +func mustHex(t testing.TB, s string) []byte { + t.Helper() + b, err := hex.DecodeString(s) + if err != nil { + t.Fatalf("Invalid hex %q: %s", s, err) + } + return b +} + +var iterations int + +func BenchmarkHashIter(b *testing.B) { + const pw = "atypical evasion foyer roulette throng awning stability exchange humorless vowed" + salt := mustHex(b, "4250af599e07cde7") + for b.Loop() { + pwhash.HashIter(pw, salt, iterations) + } +} + +func main() { + const targetDuration = 5 * time.Second + for iterations = 4096; time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) < targetDuration; iterations *= 2 { + } + lo := iterations / 2 + hi := iterations + fmt.Println(lo + sort.Search(hi-lo, func(i int) bool { + iterations = lo + i + return time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) > targetDuration + })) +} |
