Skip to content

Commit

Permalink
Use range over int in benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Feb 24, 2025
1 parent 1d2eadd commit 4a4bd11
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion completion/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func generator(match string) []string {
func TestTabCompleter_Next(t *testing.T) {
cmpl := &TabCompleter{Generate: generator}

for i := 0; i <= 9; i++ {
for i := range 10 {
num := string('0' + rune(i))
next := cmpl.Next(num)
assert.Equal(t, num, next)
Expand Down
2 changes: 1 addition & 1 deletion internal/transport/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func BenchmarkNameplateCompletion(b *testing.B) {

local := []string{}

for i := 0; i < b.N; i++ {
for range b.N {
local = c.GenerateCodeCompletion("1-letterhead-be")
}

Expand Down
4 changes: 2 additions & 2 deletions internal/transport/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func addFileIncrement(path string) (string, error) {
name = name[:len(name)-len(ext)]

// Add number at the end. Cap it to avoid doing checks forever.
for i := 1; i <= 5; i++ {
nr := strconv.Itoa(i)
for i := range 5 {
nr := strconv.Itoa(i + 1)
incremented := filepath.Join(base, name+"("+nr+")"+ext)

_, err := os.Stat(incremented)
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/tabs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func BenchmarkCreate(b *testing.B) {
b.StartTimer()

b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
tabs = Create(a, w)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/util/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestProgressReader(t *testing.T) {
}, size)

temp := [1]byte{}
for i := int64(0); i < size; i++ {
for i := range size {
_, err := teeReader.Read(temp[:])
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var globalValidationError error
func BenchmarkCodeValidator(b *testing.B) {
local := error(nil)

for i := 0; i < b.N; i++ {
for range b.N {
local = CodeValidator("125-upset-universe-mistake")
}

Expand Down

0 comments on commit 4a4bd11

Please sign in to comment.