cmd: using testing.B.Loop

Signed-off-by: yajianggroup <yajianggroup@outlook.com>
This commit is contained in:
yajianggroup 2025-09-23 16:01:10 +08:00
parent 2872242045
commit 9aba81badc

View file

@ -158,7 +158,7 @@ func timedExec(bench bool, execFunc func() ([]byte, uint64, error)) ([]byte, exe
// Do one warm-up run // Do one warm-up run
output, gasUsed, err := execFunc() output, gasUsed, err := execFunc()
result := testing.Benchmark(func(b *testing.B) { result := testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ { for b.Loop() {
haveOutput, haveGasUsed, haveErr := execFunc() haveOutput, haveGasUsed, haveErr := execFunc()
if !bytes.Equal(haveOutput, output) { if !bytes.Equal(haveOutput, output) {
panic(fmt.Sprintf("output differs\nhave %x\nwant %x\n", haveOutput, output)) panic(fmt.Sprintf("output differs\nhave %x\nwant %x\n", haveOutput, output))