aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--formatter_bench_test.go49
-rw-r--r--formatter_test.go44
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)
+ }
+}