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:
parent
39c56716bd
commit
fc6df7e651
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user