-
Notifications
You must be signed in to change notification settings - Fork 103
Add benchmarks for Quantity operations #1477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() { | ||
| q, _ := token.ToQuantity("1000000000", 128) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
|
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) | ||
| } | ||
|
theycallmeaabie marked this conversation as resolved.
|
||
| _ = r | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
theycallmeaabie marked this conversation as resolved.
|
||
| q, _ := token.ToQuantity("1000000000", 64) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
| one := token.NewOneQuantity(64) | ||
| benchResult, _ = q.Sub(one) | ||
| } | ||
|
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) | ||
| } | ||
|
theycallmeaabie marked this conversation as resolved.
|
||
| _ = r | ||
| } | ||
|
|
||
| func BenchmarkToQuantity(b *testing.B) { | ||
| for b.Loop() { | ||
| benchResult, _ = token.ToQuantity("0x1234567890abcdef", 64) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
| } | ||
|
theycallmeaabie marked this conversation as resolved.
|
||
| } | ||
|
|
||
| func ToHex(q uint64) string { | ||
| return "0x" + strconv.FormatUint(q, 16) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.