diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/finditers/finditers.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tools/finditers/finditers.go b/tools/finditers/finditers.go index cd144fa..746242b 100644 --- a/tools/finditers/finditers.go +++ b/tools/finditers/finditers.go @@ -1,8 +1,8 @@ package main import ( - "encoding/hex" "fmt" + "math/rand/v2" "os" "sort" "testing" @@ -11,18 +11,17 @@ import ( "gitlab.com/rhogenson/roseh.moe/internal/cryptoutil" ) -func mustHex(s string) []byte { - bytes, err := hex.DecodeString(s) - if err != nil { - panic(fmt.Sprintf("mustHex: bad hex %q: %s", s, err)) - } - return bytes -} - var ( iterations int - salt = mustHex("3fb84513fc3afcd6d3b230bf9ece91aaae2d2a99da17efbf7de83b21fafe3f08") + salt = func() []byte { + r := rand.New(new(rand.PCG)) + salt := make([]byte, cryptoutil.SaltSize) + for i := range salt { + salt[i] = byte(r.IntN(256)) + } + return salt + }() ) func BenchmarkHashIter(b *testing.B) { @@ -33,13 +32,15 @@ func BenchmarkHashIter(b *testing.B) { } func run() error { - for iterations = 8192; time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) < 500*time.Millisecond; iterations *= 2 { + const targetDuration = 2 * time.Second + + for iterations = 8192; 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()) > 500*time.Millisecond + return time.Duration(testing.Benchmark(BenchmarkHashIter).NsPerOp()) > targetDuration })) return nil } |
