Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Nov 2, 2021
1 parent 862154b commit a69d9ef
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
89 changes: 89 additions & 0 deletions benchmarks/xdr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package benchmarks

import (
"bytes"
"encoding/base64"
"testing"

"github.com/stellar/go/gxdr"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/require"
goxdr "github.com/xdrpp/goxdr/xdr"
)

const input64 = "AAAAAgAAAACfHrX0tYB0gpXuJYTN9os06cdF62KAaqY9jid+777eyQAAC7gCM9czAAi/DQAAAAEAAAAAAAAAAAAAAABhga2dAAAAAAAAAAMAAAAAAAAADAAAAAAAAAABTU9CSQAAAAA8cTArnmXa4wEQJxDHOw5SwBaDVjBfAP5lRMNZkRtlZAAAAAAG42RBAAf7lQCYloAAAAAAMgbg0AAAAAAAAAADAAAAAU1PQkkAAAAAPHEwK55l2uMBECcQxzsOUsAWg1YwXwD+ZUTDWZEbZWQAAAAAAAAADkpyV7kAARBNABMS0AAAAAAyBuDRAAAAAAAAAAMAAAABTU9CSQAAAAA8cTArnmXa4wEQJxDHOw5SwBaDVjBfAP5lRMNZkRtlZAAAAAAAAAAclOSvewAIl5kAmJaAAAAAADIG4NIAAAAAAAAAAe++3skAAABAs2jt6+cyeyFvXVFphBcwt18GXnj7Jwa+hWQRyaBmPOSR2415GBi8XY3lC4m4aX9S322HvHjrxgQiar7KjgnQDw=="

var input = func() []byte {
decoded, err := base64.StdEncoding.DecodeString(input64)
if err != nil {
panic(err)
}
return decoded
}()

func BenchmarkXDRUnmarshal(b *testing.B) {
b.StopTimer()
te := xdr.TransactionEnvelope{}

// Make sure the input is valid.
err := te.UnmarshalBinary(input)
require.NoError(b, err)
b.StartTimer()
// Benchmark.
for i := 0; i < b.N; i++ {
_ = te.UnmarshalBinary(input)
}
}

func BenchmarkGXDRUnmarshal(b *testing.B) {
b.StopTimer()
te := gxdr.TransactionEnvelope{}

// Make sure the input is valid, note goxdr will panic if there's a
// marshaling error.
te.XdrMarshal(&goxdr.XdrIn{In: bytes.NewReader(input)}, "")
b.StartTimer()

// Benchmark.
r := bytes.NewReader(input)
for i := 0; i < b.N; i++ {
r.Reset(input)
te.XdrMarshal(&goxdr.XdrIn{In: r}, "")
}
}

func BenchmarkXDRMarshal(b *testing.B) {
b.StopTimer()
te := xdr.TransactionEnvelope{}

// Make sure the input is valid.
err := te.UnmarshalBinary(input)
require.NoError(b, err)
output, err := te.MarshalBinary()
require.NoError(b, err)
require.Equal(b, input, output)
b.StartTimer()

// Benchmark.
for i := 0; i < b.N; i++ {
_, _ = te.MarshalBinary()
}
}

func BenchmarkGXDRMarshal(b *testing.B) {
b.StopTimer()
te := gxdr.TransactionEnvelope{}

// Make sure the input is valid, note goxdr will panic if there's a
// marshaling error.
te.XdrMarshal(&goxdr.XdrIn{In: bytes.NewReader(input)}, "")
output := bytes.Buffer{}
te.XdrMarshal(&goxdr.XdrOut{Out: &output}, "")

b.StartTimer()
// Benchmark.
for i := 0; i < b.N; i++ {
output.Reset()
te.XdrMarshal(&goxdr.XdrOut{Out: &output}, "")
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ require (
gopkg.in/square/go-jose.v2 v2.4.1
gopkg.in/tylerb/graceful.v1 v1.2.13
)

replace github.com/stellar/go-xdr => github.com/2opremio/go-xdr v0.0.0-20211102225120-4bdb08617068
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
firebase.google.com/go v3.12.0+incompatible h1:q70KCp/J0oOL8kJ8oV2j3646kV4TB8Y5IvxXC0WT1bo=
firebase.google.com/go v3.12.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs=
github.com/2opremio/go-xdr v0.0.0-20211102225120-4bdb08617068 h1:2IiaZVPzgvptivBTUBn+f+lmuv7gMdhCwhHToSd0rE8=
github.com/2opremio/go-xdr v0.0.0-20211102225120-4bdb08617068/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
Expand Down Expand Up @@ -318,8 +320,6 @@ github.com/spf13/pflag v0.0.0-20161005214240-4bd69631f475 h1:RtZIgreTwcayPTOw7G5
github.com/spf13/pflag v0.0.0-20161005214240-4bd69631f475/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189 h1:fvB1AFbBd6SfI9Rd0ooAJp8uLkZDbZaLFHi7ZnNP6uI=
github.com/spf13/viper v0.0.0-20150621231900-db7ff930a189/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
github.com/stellar/go-xdr v0.0.0-20201028102745-f80a23dac78a h1:GnM0ArRp7EDbaTiFhSp/CLgyk2cacXxdUklqJmdJs1Q=
github.com/stellar/go-xdr v0.0.0-20201028102745-f80a23dac78a/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps=
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible h1:jMXXAcz6xTarGDQ4VtVbtERogcmDQw4RaE85Cr9CgoQ=
github.com/stellar/throttled v2.2.3-0.20190823235211-89d75816f59d+incompatible/go.mod h1:7CJ23pXirXBJq45DqvO6clzTEGM/l1SfKrgrzLry8b4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit a69d9ef

Please sign in to comment.