mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
e27e5b7ffe
Hasura V3 Engine v3.alpha.12-19-2023 V3-GitOrigin-RevId: 6605575a52b347b5e9a14ecd1cc736f113c663b3 PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10567 Co-authored-by: Vishnu Bharathi <4211715+scriptnull@users.noreply.github.com> GitOrigin-RevId: 38c98a4b1971efe3ac724c2371c43ceb7d31f140
63 lines
2.0 KiB
Rust
63 lines
2.0 KiB
Rust
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
|
use engine::schema::GDS;
|
|
use hasura_authn_core::Identity;
|
|
use lang_graphql::http::Request;
|
|
use lang_graphql::parser::Parser;
|
|
use lang_graphql::validation::normalize_request;
|
|
use open_dds::permissions::Role;
|
|
use std::collections::HashMap;
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
use engine::execute;
|
|
|
|
pub fn bench_generate_ir(c: &mut Criterion) {
|
|
let test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests");
|
|
let schema = fs::read_to_string(test_dir.join("schema.json")).unwrap();
|
|
|
|
let gds = GDS::new(&schema).unwrap();
|
|
let schema = GDS::build_schema(&gds).unwrap();
|
|
|
|
let mut group = c.benchmark_group("generate_ir");
|
|
|
|
let session = Identity::admin(Role::new("admin"))
|
|
.get_role_authorization(None)
|
|
.unwrap()
|
|
.build_session(HashMap::new());
|
|
|
|
for input_file in fs::read_dir(test_dir.join("generate_ir")).unwrap() {
|
|
let entry = input_file.unwrap();
|
|
let raw_request = {
|
|
let path = entry.path();
|
|
assert!(path.is_dir());
|
|
fs::read_to_string(path.join("request.gql")).unwrap()
|
|
};
|
|
let path = entry.path();
|
|
let test_name = path.file_name().unwrap().to_str().unwrap();
|
|
|
|
let query = Parser::new(&raw_request)
|
|
.parse_executable_document()
|
|
.unwrap();
|
|
|
|
let request = Request {
|
|
operation_name: None,
|
|
query,
|
|
variables: HashMap::new(),
|
|
};
|
|
|
|
let normalized_request = normalize_request(&session.role, &schema, &request).unwrap();
|
|
|
|
group.bench_with_input(
|
|
BenchmarkId::new("generate_ir", test_name),
|
|
&(&schema, &normalized_request),
|
|
|b, (schema, normalized_request)| {
|
|
b.iter(|| execute::generate_ir(schema, &session, normalized_request).unwrap())
|
|
},
|
|
);
|
|
}
|
|
group.finish();
|
|
}
|
|
|
|
criterion_group!(benches, bench_generate_ir);
|
|
criterion_main!(benches);
|