diff options
| author | Fuwn <[email protected]> | 2026-01-31 17:40:21 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-31 17:40:21 +0000 |
| commit | e72abfc4d592ae36b230662c7430b316aa148310 (patch) | |
| tree | b16823a5cf2a4edd1055c6ae1a9303397d857bff | |
| parent | style: Use idiomatic Go test naming conventions (diff) | |
| download | iku-e72abfc4d592ae36b230662c7430b316aa148310.tar.xz iku-e72abfc4d592ae36b230662c7430b316aa148310.zip | |
refactor: Merge benchmarks into formatter_test.go
| -rw-r--r-- | formatter_bench_test.go | 49 | ||||
| -rw-r--r-- | formatter_test.go | 44 |
2 files changed, 44 insertions, 49 deletions
diff --git a/formatter_bench_test.go b/formatter_bench_test.go deleted file mode 100644 index 0820a10..0000000 --- a/formatter_bench_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "strings" - "testing" -) - -func BenchmarkFormatSmall(b *testing.B) { - inputSource := []byte(`package main -func main() { - x := 1 - y := 2 - if x > 0 { - z := 3 - } - a := 4 -} -`) - formatter := &Formatter{CommentMode: CommentsFollow} - - for b.Loop() { - _, _ = formatter.Format(inputSource) - } -} - -func BenchmarkFormatLarge(b *testing.B) { - var sourceBuilder strings.Builder - - sourceBuilder.WriteString("package main\n\n") - - for functionIndex := range 100 { - sourceBuilder.WriteString("func foo") - sourceBuilder.WriteString(string(rune('A' + functionIndex%26))) - sourceBuilder.WriteString("() {\n") - sourceBuilder.WriteString("\tx := 1\n") - sourceBuilder.WriteString("\tif x > 0 {\n") - sourceBuilder.WriteString("\t\ty := 2\n") - sourceBuilder.WriteString("\t}\n") - sourceBuilder.WriteString("\tz := 3\n") - sourceBuilder.WriteString("}\n\n") - } - - inputSource := []byte(sourceBuilder.String()) - formatter := &Formatter{CommentMode: CommentsFollow} - - for b.Loop() { - _, _ = formatter.Format(inputSource) - } -} diff --git a/formatter_test.go b/formatter_test.go index 1942bfe..efc9b6e 100644 --- a/formatter_test.go +++ b/formatter_test.go @@ -1,6 +1,7 @@ package main import ( + "strings" "testing" ) @@ -422,3 +423,46 @@ func main() { t.Errorf("got:\n%s\nwant:\n%s", formattedResult, expectedOutput) } } + +func BenchmarkFormatSmall(b *testing.B) { + inputSource := []byte(`package main +func main() { + x := 1 + y := 2 + if x > 0 { + z := 3 + } + a := 4 +} +`) + formatter := &Formatter{CommentMode: CommentsFollow} + + for b.Loop() { + _, _ = formatter.Format(inputSource) + } +} + +func BenchmarkFormatLarge(b *testing.B) { + var sourceBuilder strings.Builder + + sourceBuilder.WriteString("package main\n\n") + + for functionIndex := range 100 { + sourceBuilder.WriteString("func foo") + sourceBuilder.WriteString(string(rune('A' + functionIndex%26))) + sourceBuilder.WriteString("() {\n") + sourceBuilder.WriteString("\tx := 1\n") + sourceBuilder.WriteString("\tif x > 0 {\n") + sourceBuilder.WriteString("\t\ty := 2\n") + sourceBuilder.WriteString("\t}\n") + sourceBuilder.WriteString("\tz := 3\n") + sourceBuilder.WriteString("}\n\n") + } + + inputSource := []byte(sourceBuilder.String()) + formatter := &Formatter{CommentMode: CommentsFollow} + + for b.Loop() { + _, _ = formatter.Format(inputSource) + } +} |