Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions token/token/quantity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,66 @@ func TestUInt64Quantity_Clone(t *testing.T) {
assert.Equal(t, "100", clone.Decimal())
}

var benchResult token.Quantity

func BenchmarkBigQuantity_Add(b *testing.B) {
for b.Loop() {
q := token.NewZeroQuantity(128)
one := token.NewOneQuantity(128)
benchResult, _ = q.Add(one)
}
}

func BenchmarkBigQuantity_Sub(b *testing.B) {
for b.Loop() {
Comment thread
theycallmeaabie marked this conversation as resolved.
q, _ := token.ToQuantity("1000000000", 128)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please assert on errors and not ignoring it?

This comment is relevant for all other places in these methods.

one := token.NewOneQuantity(128)
benchResult, _ = q.Sub(one)
}
Comment thread
theycallmeaabie marked this conversation as resolved.
}

func BenchmarkBigQuantity_Cmp(b *testing.B) {
q := token.NewZeroQuantity(128)
one := token.NewOneQuantity(128)
var r int
for b.Loop() {
r = q.Cmp(one)
}
Comment thread
theycallmeaabie marked this conversation as resolved.
_ = r
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See copilot error.

}

func BenchmarkUInt64Quantity_Add(b *testing.B) {
for b.Loop() {
q := token.NewZeroQuantity(64)
one := token.NewOneQuantity(64)
benchResult, _ = q.Add(one)
}
}

func BenchmarkUInt64Quantity_Sub(b *testing.B) {
for b.Loop() {
Comment thread
theycallmeaabie marked this conversation as resolved.
q, _ := token.ToQuantity("1000000000", 64)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not ignore errors. Assert on errors:

q, _ := token.ToQuantity("1000000000", 64)
require.NoError(t, err)

one := token.NewOneQuantity(64)
benchResult, _ = q.Sub(one)
}
Comment thread
theycallmeaabie marked this conversation as resolved.
}

func BenchmarkUInt64Quantity_Cmp(b *testing.B) {
q := token.NewZeroQuantity(64)
one := token.NewOneQuantity(64)
var r int
for b.Loop() {
r = q.Cmp(one)
}
Comment thread
theycallmeaabie marked this conversation as resolved.
_ = r
}

func BenchmarkToQuantity(b *testing.B) {
for b.Loop() {
benchResult, _ = token.ToQuantity("0x1234567890abcdef", 64)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not ignore errors. Assert on errors:

benchResult, err = token.ToQuantity("0x1234567890abcdef", 64)
require.NoError(t, err)

}
Comment thread
theycallmeaabie marked this conversation as resolved.
}

func ToHex(q uint64) string {
return "0x" + strconv.FormatUint(q, 16)
}
Expand Down
Loading