Merge pull request #5072 from cfromknecht/fix-tlv-bench
tlv: fix ESatPerKw in benchmark
This commit is contained in:
commit
dd13dbe613
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
"github.com/lightningnetwork/lnd/watchtower/blob"
|
"github.com/lightningnetwork/lnd/watchtower/blob"
|
||||||
"github.com/lightningnetwork/lnd/watchtower/wtwire"
|
"github.com/lightningnetwork/lnd/watchtower/wtwire"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateSessionTLV mirrors the wtwire.CreateSession message, but uses TLV for
|
// CreateSessionTLV mirrors the wtwire.CreateSession message, but uses TLV for
|
||||||
@ -49,7 +50,8 @@ func DBlobType(r io.Reader, val interface{}, buf *[8]byte, l uint64) error {
|
|||||||
// ESatPerKW is an encoder for lnwallet.SatPerKWeight.
|
// ESatPerKW is an encoder for lnwallet.SatPerKWeight.
|
||||||
func ESatPerKW(w io.Writer, val interface{}, buf *[8]byte) error {
|
func ESatPerKW(w io.Writer, val interface{}, buf *[8]byte) error {
|
||||||
if v, ok := val.(*chainfee.SatPerKWeight); ok {
|
if v, ok := val.(*chainfee.SatPerKWeight); ok {
|
||||||
return tlv.EUint64(w, uint64(*v), buf)
|
v64 := uint64(*v)
|
||||||
|
return tlv.EUint64(w, &v64, buf)
|
||||||
}
|
}
|
||||||
return tlv.NewTypeForEncodingErr(val, "chainfee.SatPerKWeight")
|
return tlv.NewTypeForEncodingErr(val, "chainfee.SatPerKWeight")
|
||||||
}
|
}
|
||||||
@ -104,7 +106,7 @@ func BenchmarkEncodeCreateSession(t *testing.B) {
|
|||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
err = m.Encode(ioutil.Discard, 0)
|
err = m.Encode(ioutil.Discard, 0)
|
||||||
}
|
}
|
||||||
_ = err
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkEncodeCreateSessionTLV benchmarks encoding of the TLV CreateSession.
|
// BenchmarkEncodeCreateSessionTLV benchmarks encoding of the TLV CreateSession.
|
||||||
@ -118,7 +120,7 @@ func BenchmarkEncodeCreateSessionTLV(t *testing.B) {
|
|||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
err = m.Encode(ioutil.Discard)
|
err = m.Encode(ioutil.Discard)
|
||||||
}
|
}
|
||||||
_ = err
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkDecodeCreateSession benchmarks encoding of the non-TLV
|
// BenchmarkDecodeCreateSession benchmarks encoding of the non-TLV
|
||||||
@ -127,18 +129,19 @@ func BenchmarkDecodeCreateSession(t *testing.B) {
|
|||||||
m := &wtwire.CreateSession{}
|
m := &wtwire.CreateSession{}
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
m.Encode(&b, 0)
|
err := m.Encode(&b, 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
r := bytes.NewReader(b.Bytes())
|
r := bytes.NewReader(b.Bytes())
|
||||||
|
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
var err error
|
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
r.Seek(0, 0)
|
r.Seek(0, 0)
|
||||||
err = m.Decode(r, 0)
|
err = m.Decode(r, 0)
|
||||||
}
|
}
|
||||||
_ = err
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkDecodeCreateSessionTLV benchmarks decoding of the TLV CreateSession.
|
// BenchmarkDecodeCreateSessionTLV benchmarks decoding of the TLV CreateSession.
|
||||||
@ -146,8 +149,9 @@ func BenchmarkDecodeCreateSessionTLV(t *testing.B) {
|
|||||||
m := NewCreateSessionTLV()
|
m := NewCreateSessionTLV()
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
var err error
|
err := m.Encode(&b)
|
||||||
m.Encode(&b)
|
require.NoError(t, err)
|
||||||
|
|
||||||
r := bytes.NewReader(b.Bytes())
|
r := bytes.NewReader(b.Bytes())
|
||||||
|
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
@ -157,5 +161,5 @@ func BenchmarkDecodeCreateSessionTLV(t *testing.B) {
|
|||||||
r.Seek(0, 0)
|
r.Seek(0, 0)
|
||||||
err = m.Decode(r)
|
err = m.Decode(r)
|
||||||
}
|
}
|
||||||
_ = err
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user