Debian Codegraph @

benches/subresources.rs

raw symbols SCIP
1 use codspeed_criterion_compat::{
2 black_box, criterion_group, criterion_main, BenchmarkId, Criterion,
3 };
4 use referencing::Draft;
5
6 static DRAFT4: &[u8] = include_bytes!("../../benchmark/data/subresources/draft4.json");
7 static DRAFT6: &[u8] = include_bytes!("../../benchmark/data/subresources/draft6.json");
8 static DRAFT7: &[u8] = include_bytes!("../../benchmark/data/subresources/draft7.json");
9 static DRAFT201909: &[u8] = include_bytes!("../../benchmark/data/subresources/draft201909.json");
10 static DRAFT202012: &[u8] = include_bytes!("../../benchmark/data/subresources/draft202012.json");
11
12 fn bench_subresources(c: &mut Criterion) {
13 let drafts = [
14 (Draft::Draft4, DRAFT4, "draft 4"),
15 (Draft::Draft6, DRAFT6, "draft 6"),
16 (Draft::Draft7, DRAFT7, "draft 7"),
17 (Draft::Draft201909, DRAFT201909, "draft 2019-09"),
18 (Draft::Draft202012, DRAFT202012, "draft 2020-12"),
19 (Draft::Draft4, benchmark::GEOJSON, "GeoJSON"),
20 (Draft::Draft4, benchmark::SWAGGER, "Swagger"),
21 (Draft::Draft4, benchmark::OPEN_API, "Open API"),
22 (Draft::Draft4, benchmark::CITM_SCHEMA, "CITM"),
23 (Draft::Draft7, benchmark::FAST_SCHEMA, "Fast"),
24 ];
25
26 let mut group = c.benchmark_group("subresources");
27
28 for (draft, data, name) in &drafts {
29 let schema = benchmark::read_json(data);
30
31 group.bench_with_input(
32 BenchmarkId::new("subresources_of", name),
33 &schema,
34 |b, schema| {
35 b.iter(|| {
36 for sub in draft.subresources_of(black_box(schema)) {
37 let _ = sub;
38 }
39 });
40 },
41 );
42 }
43
44 group.finish();
45 }
46
47 criterion_group!(benches, bench_subresources);
48 criterion_main!(benches);