aboutsummaryrefslogtreecommitdiff
path: root/formatter_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'formatter_test.go')
-rw-r--r--formatter_test.go44
1 files changed, 44 insertions, 0 deletions
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)
+ }
+}