aboutsummaryrefslogtreecommitdiff
path: root/formatter_bench_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'formatter_bench_test.go')
-rw-r--r--formatter_bench_test.go48
1 files changed, 24 insertions, 24 deletions
diff --git a/formatter_bench_test.go b/formatter_bench_test.go
index 53f607b..2a6d3cd 100644
--- a/formatter_bench_test.go
+++ b/formatter_bench_test.go
@@ -5,8 +5,8 @@ import (
"testing"
)
-func BenchmarkFormat_Small(b *testing.B) {
- input := []byte(`package main
+func BenchmarkFormat_Small(benchmarkRunner *testing.B) {
+ inputSource := []byte(`package main
func main() {
x := 1
y := 2
@@ -16,34 +16,34 @@ func main() {
a := 4
}
`)
- f := &Formatter{CommentMode: CommentsFollow}
+ formatter := &Formatter{CommentMode: CommentsFollow}
- for b.Loop() {
- _, _ = f.Format(input)
+ for benchmarkRunner.Loop() {
+ _, _ = formatter.Format(inputSource)
}
}
-func BenchmarkFormat_Large(b *testing.B) {
- var sb strings.Builder
-
- sb.WriteString("package main\n\n")
-
- for i := range 100 {
- sb.WriteString("func foo")
- sb.WriteString(string(rune('A' + i%26)))
- sb.WriteString("() {\n")
- sb.WriteString("\tx := 1\n")
- sb.WriteString("\tif x > 0 {\n")
- sb.WriteString("\t\ty := 2\n")
- sb.WriteString("\t}\n")
- sb.WriteString("\tz := 3\n")
- sb.WriteString("}\n\n")
+func BenchmarkFormat_Large(benchmarkRunner *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")
}
- input := []byte(sb.String())
- f := &Formatter{CommentMode: CommentsFollow}
+ inputSource := []byte(sourceBuilder.String())
+ formatter := &Formatter{CommentMode: CommentsFollow}
- for b.Loop() {
- _, _ = f.Format(input)
+ for benchmarkRunner.Loop() {
+ _, _ = formatter.Format(inputSource)
}
}