Skip to content

Commit

Permalink
style: for range N
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Feb 28, 2024
1 parent 564d3a6 commit 252b8b8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestBalanceLedger(t *testing.T) {

func BenchmarkGetBalances(b *testing.B) {
var trans []*Transaction
for i := 0; i < 100000; i++ {
for i := range 100000 {
a := rand.Intn(50)
b := rand.Intn(10)
c := rand.Intn(5)
Expand All @@ -115,7 +115,7 @@ func BenchmarkGetBalances(b *testing.B) {
})
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range b.N {
GetBalances(trans, []string{})
}
}
Expand Down
2 changes: 1 addition & 1 deletion decimal/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (d Decimal) Cmp(d1 Decimal) int {
// output bytes begin and the value v/10**prec.
func fmtFrac(buf []byte, v uint64, prec int) (nw int, nv uint64) {
w := len(buf)
for i := 0; i < prec; i++ {
for range prec {
digit := v % 10
w--
buf[w] = byte(digit) + '0'
Expand Down
6 changes: 3 additions & 3 deletions decimal/decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func FuzzStringParse(f *testing.F) {

func BenchmarkNewFromString(b *testing.B) {
numbers := []string{"10.0", "245.6", "354", "2.456", "-31.2"}
for n := 0; n < b.N; n++ {
for range b.N {
for _, numStr := range numbers {
NewFromString(numStr)
}
Expand All @@ -423,14 +423,14 @@ func BenchmarkNewFromString(b *testing.B) {

func BenchmarkStringFixedBank(b *testing.B) {
var numbers [1000]Decimal
for i := 0; i < len(numbers); i++ {
for i := range len(numbers) {
numbers[i] = NewFromFloat(rand.Float64() * 100000)
if i%2 == 0 {
numbers[i] *= -1
}
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
for range b.N {
for _, num := range numbers {
num.StringFixedBank()
}
Expand Down
2 changes: 1 addition & 1 deletion parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ account endofledger`)
}

func BenchmarkParseLedger(b *testing.B) {
for n := 0; n < b.N; n++ {
for range b.N {
_, _ = ParseLedgerFile("testdata/ledgerBench.dat")
}
}

0 comments on commit 252b8b8

Please sign in to comment.