-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial benchmark tests for basic queries; something we can work upon…
… from here for perf-related PRs. - simple hello world equivalent - with a list - deeper query with list - query with many root fields and list in each of them - deeper query with many root fields and lists To really bring out probable issues with query perf, a latency is introduced to the data retrieval (previously it was just in-memory data fetch) When testing against branch before PR #20 and #21, this really highlighted the problem with evaluating list fields. In the future, more benchmarks for queries with fragments probably would be useful.
- Loading branch information
Showing
2 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
package graphql_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/graphql-go/graphql" | ||
"github.com/graphql-go/graphql/testutil" | ||
) | ||
|
||
// to avoid possible compiler optimization | ||
var benchmark_result *graphql.Result | ||
|
||
func benchmarkQuery(b *testing.B, schema graphql.Schema, query string) { | ||
params := graphql.Params{ | ||
Schema: testutil.StarWarsSchema, | ||
RequestString: query, | ||
} | ||
|
||
var result *graphql.Result | ||
for n := 0; n < b.N; n++ { | ||
result = graphql.Do(params) | ||
} | ||
benchmark_result = result | ||
} | ||
|
||
func BenchmarkQuery_BasicQuery(b *testing.B) { | ||
query := ` | ||
{ | ||
hero { | ||
name | ||
} | ||
} | ||
` | ||
benchmarkQuery(b, testutil.StarWarsSchema, query) | ||
} | ||
|
||
func BenchmarkQuery_BasicQueryWithList(b *testing.B) { | ||
query := ` | ||
{ | ||
hero { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
} | ||
appearsIn | ||
} | ||
} | ||
` | ||
benchmarkQuery(b, testutil.StarWarsSchema, query) | ||
} | ||
|
||
func BenchmarkQuery_DeeperQueryWithList(b *testing.B) { | ||
query := ` | ||
{ | ||
hero { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
appearsIn | ||
} | ||
appearsIn | ||
} | ||
} | ||
` | ||
benchmarkQuery(b, testutil.StarWarsSchema, query) | ||
} | ||
|
||
func BenchmarkQuery_QueryWithManyRootFieldsAndList(b *testing.B) { | ||
query := ` | ||
{ | ||
hero { | ||
id | ||
name | ||
friends { | ||
name | ||
} | ||
appearsIn | ||
} | ||
vader: human(id: "1001") { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
appearsIn | ||
homePlanet | ||
} | ||
leia: human(id: "1003") { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
appearsIn | ||
homePlanet | ||
} | ||
threepio: droid(id: "2000") { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
appearsIn | ||
PrimaryFunction | ||
} | ||
artoo: droid(id: "2001") { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
appearsIn | ||
PrimaryFunction | ||
} | ||
} | ||
` | ||
benchmarkQuery(b, testutil.StarWarsSchema, query) | ||
} | ||
|
||
func BenchmarkQuery_DeeperQueryWithManyRootFieldsAndList(b *testing.B) { | ||
query := ` | ||
{ | ||
hero { | ||
id | ||
name | ||
friends { | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
} | ||
appearsIn | ||
} | ||
vader: human(id: "1001") { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
} | ||
appearsIn | ||
homePlanet | ||
} | ||
leia: human(id: "1003") { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
} | ||
appearsIn | ||
homePlanet | ||
} | ||
threepio: droid(id: "2000") { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
} | ||
appearsIn | ||
PrimaryFunction | ||
} | ||
artoo: droid(id: "2001") { | ||
id | ||
name | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
friends { | ||
id | ||
name | ||
appearsIn | ||
} | ||
} | ||
appearsIn | ||
PrimaryFunction | ||
} | ||
} | ||
` | ||
benchmarkQuery(b, testutil.StarWarsSchema, query) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters