diff --git a/core/internal/qcode/parse_test.go b/core/internal/qcode/parse_test.go index 968ac03..c146dc7 100644 --- a/core/internal/qcode/parse_test.go +++ b/core/internal/qcode/parse_test.go @@ -2,6 +2,7 @@ package qcode import ( "errors" + "github.com/chirino/graphql/schema" "testing" ) @@ -130,7 +131,7 @@ updateThread { } var gql = []byte(` - products( + {products( # returns only 30 items limit: 30, @@ -148,7 +149,7 @@ var gql = []byte(` id name price - }`) + }}`) func BenchmarkQCompile(b *testing.B) { qcompile, _ := NewCompiler(Config{}) @@ -181,3 +182,59 @@ func BenchmarkQCompileP(b *testing.B) { } }) } + +func BenchmarkParse(b *testing.B) { + + b.ResetTimer() + b.ReportAllocs() + for n := 0; n < b.N; n++ { + _, err := Parse(gql) + + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkParseP(b *testing.B) { + b.ResetTimer() + b.ReportAllocs() + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + _, err := Parse(gql) + + if err != nil { + b.Fatal(err) + } + } + }) +} + +func BenchmarkSchemaParse(b *testing.B) { + + b.ResetTimer() + b.ReportAllocs() + for n := 0; n < b.N; n++ { + doc := schema.QueryDocument{} + err := doc.Parse(string(gql)) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkSchemaParseP(b *testing.B) { + b.ResetTimer() + b.ReportAllocs() + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + doc := schema.QueryDocument{} + err := doc.Parse(string(gql)) + if err != nil { + b.Fatal(err) + } + } + }) +}