refactor: use b.Loop() to simplify the code and improve performance (#25368)

Signed-off-by: withtimezone <with_timezone@outlook.com>
This commit is contained in:
withtimezone
2025-09-29 11:32:54 -04:00
committed by GitHub
parent 39c56716bd
commit fc6df7e651
2 changed files with 5 additions and 10 deletions
+4 -8
View File
@@ -33,8 +33,7 @@ func BenchmarkLegacyGetSigners(b *testing.B) {
Amount: nil,
}}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = msg.GetSigners()
}
}
@@ -50,8 +49,7 @@ func BenchmarkProtoreflectGetSigners(b *testing.B) {
Amount: nil,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, err := signingCtx.GetSigners(msg)
if err != nil {
panic(err)
@@ -72,8 +70,7 @@ func BenchmarkProtoreflectGetSignersWithUnmarshal(b *testing.B) {
a, err := codectypes.NewAnyWithValue(msg)
require.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _, err := cdc.GetMsgAnySigners(a)
if err != nil {
panic(err)
@@ -97,8 +94,7 @@ func BenchmarkProtoreflectGetSignersDynamicpb(b *testing.B) {
err = protov2.Unmarshal(bz, dynamicmsg)
require.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_, err := signingCtx.GetSigners(dynamicmsg)
if err != nil {
panic(err)
+1 -2
View File
@@ -165,10 +165,9 @@ func BenchmarkProtoCodecMarshalLengthPrefixed(b *testing.B) {
}),
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
blob, err := pCdc.MarshalLengthPrefixed(msg)
if err != nil {
b.Fatal(err)