-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go test -benchtime=5s -bench=. -benchmem goos: linux goarch: amd64 pkg: github.com/99designs/gqlgen/example/starwars BenchmarkSimpleQueryNoArgs-8 200000 32680 ns/op 6357 B/op 126 allocs/op PASS ok github.com/99designs/gqlgen/example/starwars 9.901s
- Loading branch information
Showing
2 changed files
with
32 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 |
---|---|---|
|
@@ -7,3 +7,5 @@ | |
/codegen/gen | ||
|
||
.idea/ | ||
*.test | ||
*.out |
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,30 @@ | ||
package starwars | ||
|
||
import ( | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/99designs/gqlgen/handler" | ||
) | ||
|
||
func BenchmarkSimpleQueryNoArgs(b *testing.B) { | ||
server := handler.GraphQL(NewExecutableSchema(NewResolver())) | ||
|
||
q := `{"query":"{ search(text:\"Luke\") { ... on Human { starships { name } } } }"}` | ||
|
||
var body strings.Reader | ||
r := httptest.NewRequest("POST", "/graphql", &body) | ||
|
||
b.ResetTimer() | ||
rec := httptest.NewRecorder() | ||
for i := 0; i < b.N; i++ { | ||
body.Reset(q) | ||
rec.Body.Reset() | ||
server.ServeHTTP(rec, r) | ||
if rec.Body.String() != `{"data":{"search":[{"starships":[{"name":"X-Wing"},{"name":"Imperial shuttle"}]}]}}` { | ||
b.Fatalf("Unexpected response") | ||
} | ||
|
||
} | ||
} |