MCPcopy
hub / github.com/dgraph-io/dgraph / BenchmarkMutation

Function BenchmarkMutation

graphql/bench/auth_test.go:498–544  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

496}
497
498func BenchmarkMutation(b *testing.B) {
499 schemaFile := "schema_auth.graphql"
500 schema, err := os.ReadFile(schemaFile)
501 require.NoError(b, err)
502
503 metaInfo := getAuthMeta(string(schema))
504 metaInfo.AuthVars = map[string]interface{}{
505 "Role": "ADMIN",
506 "USERNAME": "$",
507 }
508
509 owners := generateOwnerRestaurant(100)
510 owners.add(b, metaInfo)
511
512 query := `
513 query {
514 queryRestaurant (first: 300000) {
515 id
516 name
517 owner {
518 username
519 }
520 }
521 }
522 `
523
524 getUserParams := &common.GraphQLParams{
525 Headers: getJWT(b, metaInfo),
526 Query: query,
527 }
528
529 var totalTime time.Duration
530 for i := 0; i < b.N; i++ {
531 before := time.Now()
532 gqlResponse := getUserParams.ExecuteAsPost(b, graphqlURL)
533 require.Nilf(b, gqlResponse.Errors, "%+v", gqlResponse.Errors)
534 reqTime := time.Since(before)
535 totalTime += reqTime
536 if i%10 == 0 {
537 avgTime := int64(totalTime) / (int64(i + 1))
538 fmt.Printf("Avg Time: %d Time: %d \n", avgTime, reqTime)
539 }
540 // Stopping the timer as we don't want to include the clean up time in benchmark result.
541 b.StopTimer()
542 clearAll(b, metaInfo)
543 }
544}

Callers

nothing calls this directly

Calls 6

ExecuteAsPostMethod · 0.95
getAuthMetaFunction · 0.85
generateOwnerRestaurantFunction · 0.85
getJWTFunction · 0.85
clearAllFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected