Modernize benchmarks

See https://go.dev/blog/testing-b-loop
This commit is contained in:
Stefan Haller 2025-04-18 21:30:24 +02:00
parent 14eb4c29ca
commit 4cfa6e0c98
3 changed files with 6 additions and 6 deletions

View file

@ -691,7 +691,7 @@ keybinding:
`)
func BenchmarkMigrationOnLargeConfiguration(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _ = computeMigratedConfig("path doesn't matter", largeConfiguration)
}
}

View file

@ -548,7 +548,7 @@ func BenchmarkRenderCommitGraph(b *testing.B) {
return authors.AuthorStyle(commit.AuthorName)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
RenderCommitGraph(commits, "selected", getStyle)
}
}

View file

@ -253,25 +253,25 @@ func TestRenderDisplayStrings(t *testing.T) {
}
func BenchmarkStringWidthAsciiOriginal(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
runewidth.StringWidth("some ASCII string")
}
}
func BenchmarkStringWidthAsciiOptimized(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
StringWidth("some ASCII string")
}
}
func BenchmarkStringWidthNonAsciiOriginal(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
runewidth.StringWidth("some non-ASCII string 🍉")
}
}
func BenchmarkStringWidthNonAsciiOptimized(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
StringWidth("some non-ASCII string 🍉")
}
}