All benchmarks must be Criterion benchmarks. (#498)

This ensures only Criterion benchmarks get called by `cargo bench`.
Previously, some tests were being loaded too. This is an issue because
if we want to provide command-line arguments to Criterion, it will fail
if we run a non-Criterion benchmark.

We need to specify `harness = false` for each benchmark so that they
don't get wrapped by Cargo, and `bench = false` for everything that
doesn't contain benchmarks but _could_ (i.e. unit and integration
tests). I find Cargo very strange in this regard.

In addition, I fixed the validation benchmark by providing a valid SDL
schema.

V3_GIT_ORIGIN_REV_ID: 338ac5b1411eec7af32923863c5b6f3933c0454b
This commit is contained in:
Samir Talwar 2024-04-23 14:59:38 +02:00 committed by hasura-bot
parent 09282cb304
commit 2c2ffa05bf
5 changed files with 15 additions and 5 deletions

View File

@ -18,6 +18,10 @@ bench = false
name = "execute"
harness = false
[[bench]]
name = "generate_ir"
harness = false
[dependencies]
hasura-authn-core = { path = "../hasura-authn-core" }
hasura-authn-jwt = { path = "../hasura-authn-jwt" }

View File

@ -17,7 +17,7 @@ pub fn bench_validation(c: &mut Criterion) {
// benches/queries/<file_name>.graphql -> <file_name>
let query_name = query_path.file_stem().unwrap().to_str().unwrap();
let parsed_query = Parser::new(&query).parse_executable_document().unwrap();
let schema = sdl::SDL::new("type Query {}")
let fake_schema = sdl::SDL::new("type Query {foo: Int}")
.and_then(|v| v.build_schema())
.unwrap();
let request = http::Request {
@ -25,13 +25,13 @@ pub fn bench_validation(c: &mut Criterion) {
query: parsed_query,
variables: HashMap::new(),
};
validation::normalize_request(&sdl::Namespace, &schema, &request).unwrap();
validation::normalize_request(&sdl::Namespace, &fake_schema, &request).unwrap();
// parse with our parser
group.bench_with_input(
BenchmarkId::new("hasura", query_name),
&(&request, &schema),
|b, (request, default_schema)| {
b.iter(|| validation::normalize_request(&sdl::Namespace, default_schema, request))
&(request, fake_schema),
|b, (request, schema)| {
b.iter(|| validation::normalize_request(&sdl::Namespace, schema, request).unwrap())
},
);
}

View File

@ -4,6 +4,11 @@ version.workspace = true
edition.workspace = true
license.workspace = true
[[bin]]
name = "metadata-schema-generator"
path = "src/main.rs"
bench = false
[dependencies]
open-dds = { path = "../open-dds" }
serde_json = "1.0.92"

View File

@ -5,6 +5,7 @@ edition = "2021"
[lib]
proc-macro = true
bench = false
[dependencies]
syn = { version = "1.0", features = ["full"] }