fix: benchmark was failing. Also added a benchmark for the chirino/graphql version gql parser to compare results. (#62)

This commit is contained in:
Hiram Chirino 2020-05-07 10:48:01 -04:00 committed by GitHub
parent 84d55dbc8a
commit 533c767e1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 59 additions and 2 deletions

View File

@ -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)
}
}
})
}