Skip to content

Commit

Permalink
Optimize asset string conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Dec 11, 2021
1 parent e80796c commit bb97831
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xdr/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (a Asset) StringCanonical() string {
return t
}

return fmt.Sprintf("%s:%s", c, i)
return c + ":" + i
}

// Equals returns true if `other` is equivalent to `a`
Expand Down
30 changes: 30 additions & 0 deletions xdr/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,33 @@ func TestAssetLessThan(t *testing.T) {
assert.False(t, assetIssuerB.LessThan(assetIssuerB))
})
}

func BenchmarkAssetString(b *testing.B) {
n := MustNewNativeAsset()
a, err := NewCreditAsset(
"ARST",
"GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO",
)
require.NoError(b, err)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = n.String()
_ = a.String()
}
}

func BenchmarkAssetStringCanonical(b *testing.B) {
n := MustNewNativeAsset()
a, err := NewCreditAsset(
"ARST",
"GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO",
)
require.NoError(b, err)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = n.StringCanonical()
_ = a.StringCanonical()
}
}

0 comments on commit bb97831

Please sign in to comment.