-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): add a benchmark for #862
- Loading branch information
1 parent
ad30e71
commit 5b9875b
Showing
2 changed files
with
56 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
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,51 @@ | ||
use apollo_compiler::ExecutableDocument; | ||
use apollo_compiler::Schema; | ||
use criterion::*; | ||
use std::fmt::Write; | ||
|
||
fn bench_big_schema_many_fragments(c: &mut Criterion) { | ||
const NUM_INTERFACES: usize = 200; | ||
const NUM_OBJECTS: usize = 10_000; | ||
|
||
let mut sdl = String::new(); | ||
for i in 0..NUM_INTERFACES { | ||
_ = writeln!(&mut sdl, r#"interface Intf{i} {{ field: Int! }}"#); | ||
} | ||
for o in 0..NUM_OBJECTS { | ||
let i = o % NUM_INTERFACES; | ||
_ = writeln!( | ||
&mut sdl, | ||
r#"type Ty{o} implements Intf{i} {{ field: Int! }}"# | ||
); | ||
} | ||
|
||
_ = writeln!(&mut sdl, "type Query {{"); | ||
for i in 0..NUM_INTERFACES { | ||
_ = writeln!(&mut sdl, " intf{i}: Intf{i}"); | ||
} | ||
_ = writeln!(&mut sdl, "}}"); | ||
|
||
let schema = Schema::parse_and_validate(sdl, "schema.graphql").unwrap(); | ||
let mut selection = String::new(); | ||
let mut fragments = String::new(); | ||
for i in 0..NUM_INTERFACES { | ||
_ = writeln!(&mut selection, " intf{i} {{ ...frag{i} }}"); | ||
_ = writeln!(&mut fragments, "fragment frag{i} on Ty{i} {{ field }}"); | ||
} | ||
let query = format!( | ||
"query {{ | ||
{selection}}} | ||
{fragments}" | ||
); | ||
|
||
c.bench_function("big_schema_many_fragments", move |b| { | ||
b.iter(|| { | ||
let doc = | ||
ExecutableDocument::parse_and_validate(&schema, &query, "query.graphql").unwrap(); | ||
black_box(doc); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(fragments, bench_big_schema_many_fragments,); | ||
criterion_main!(fragments); |