From 28b64c3dd1bbed21107d5198a9a7a286388c0698 Mon Sep 17 00:00:00 2001 From: Erik Wrede Date: Tue, 21 May 2024 10:29:03 +0200 Subject: [PATCH] chore: add more benchmarks --- .../benchmarks/test_core_full_schema_bench.py | 363 +++++++++++++++++- 1 file changed, 352 insertions(+), 11 deletions(-) diff --git a/test_parser/benchmarks/test_core_full_schema_bench.py b/test_parser/benchmarks/test_core_full_schema_bench.py index 94edaa1..1387a22 100644 --- a/test_parser/benchmarks/test_core_full_schema_bench.py +++ b/test_parser/benchmarks/test_core_full_schema_bench.py @@ -21,7 +21,6 @@ def resolve_fruits(root, info): ] def resolve_conference(root, info, id): - print("i was called") # Here, you'd typically fetch conference data from a database or an API. # For the sake of this example, we're returning static data. if id == "pycon-it-2024": @@ -235,9 +234,314 @@ def __init__(self): } } } +""" +operation_xxlarge = """ +query ConferenceQuery { + a: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + b: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + c: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + d: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + e: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + f: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + g: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + h: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + i: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + j: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + k: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + l: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + m: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + n: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + o: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + p: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + q: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + r: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + s: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } + t: conference(id: "pycon-it-2024") { + name + description + talks { + title + speaker { + name + github + } + } + faqs { + question + answer + } + } +} """ + from graphql.utilities import get_introspection_query, build_client_schema from graphql import parse, print_schema @@ -250,7 +554,7 @@ def __init__(self): @pytest.mark.benchmark -def test_full_graphql_core(): +def test_full__graphql_core(): query = parse(operation) validation_errors = validate(schema, query) validation_success = not validation_errors @@ -264,7 +568,7 @@ def test_full_graphql_core(): @pytest.mark.benchmark -def test_full_rustberry(): +def test_full__rustberry(): document = compiler.parse(operation) validation_success = compiler.validate(document) query = compiler.gql_core_ast_mirror(document) @@ -275,7 +579,7 @@ def test_full_rustberry(): schema, query, ) @pytest.mark.benchmark -def test_full_rustberry_no_mirror(): +def test_full__rustberry_no_mirror(): document = compiler.parse(operation) validation_success = compiler.validate(document) query = compiler.gql_core_ast(document) @@ -288,7 +592,7 @@ def test_full_rustberry_no_mirror(): @pytest.mark.benchmark -def test_full_large_graphql_core(): +def test_full_large__graphql_core(): query = parse(operation_large) validation_errors = validate(schema, query) validation_success = not validation_errors @@ -301,7 +605,7 @@ def test_full_large_graphql_core(): ) @pytest.mark.benchmark -def test_full_large_rustberry(): +def test_full_large__rustberry(): document = compiler.parse(operation_large) validation_success = compiler.validate(document) query = compiler.gql_core_ast_mirror(document) @@ -313,7 +617,7 @@ def test_full_large_rustberry(): ) @pytest.mark.benchmark -def test_full_large_rustberry_no_mirror(): +def test_full_large__rustberry_no_mirror(): document = compiler.parse(operation_large) validation_success = compiler.validate(document) query = compiler.gql_core_ast(document) @@ -324,18 +628,55 @@ def test_full_large_rustberry_no_mirror(): schema, query, ) +@pytest.mark.benchmark +def test_full_xlarge__graphql_core(): + query = parse(operation_xxlarge) + validation_errors = validate(schema, query) + validation_success = not validation_errors + + if not validation_success: + return ExecutionResult(data=None, errors=validation_errors) + + e = execute( + schema, query, + ) + +@pytest.mark.benchmark +def test_full_xxlarge__rustberry(): + document = compiler.parse(operation_xxlarge) + validation_success = compiler.validate(document) + query = compiler.gql_core_ast_mirror(document) + if not validation_success: + return ExecutionResult(data=None, errors=validation_errors) + + e = execute( + schema, query, + ) + +@pytest.mark.benchmark +def test_full_xxlarge__rustberry_no_mirror(): + document = compiler.parse(operation_xxlarge) + validation_success = compiler.validate(document) + query = compiler.gql_core_ast(document) + if not validation_success: + return ExecutionResult(data=None, errors=validation_errors) + + e = execute( + schema, query, + ) + @pytest.mark.benchmark def test_pure_execution_core(benchmark): query = parse(operation) benchmark(execute, schema, query) @pytest.mark.benchmark -def test_pure_execution_rustberry(benchmark): +def test_pure_execution__rustberry(benchmark): document = compiler.parse(operation) query = compiler.gql_core_ast_mirror(document) benchmark(execute, schema, query) @pytest.mark.benchmark -def test_pure_execution_rustberry_no_mirror(benchmark): +def test_pure_execution__rustberry_no_mirror(benchmark): document = compiler.parse(operation) query = compiler.gql_core_ast(document) benchmark(execute, schema, query) @@ -348,13 +689,13 @@ def test_pure_execution_core_large(benchmark): benchmark(execute, schema, query) @pytest.mark.benchmark -def test_pure_execution_large_rustberry(benchmark): +def test_pure_execution_large__rustberry(benchmark): document = compiler.parse(operation_large) query = compiler.gql_core_ast_mirror(document) benchmark(execute, schema, query) @pytest.mark.benchmark -def test_pure_execution_large_rustberry_no_mirror(benchmark): +def test_pure_execution_large__rustberry_no_mirror(benchmark): document = compiler.parse(operation_large) query = compiler.gql_core_ast(document) #print(print_ast(query))