Debian Codegraph @

benches/anchor.rs

raw symbols SCIP
1 use codspeed_criterion_compat::{
2 black_box, criterion_group, criterion_main, BenchmarkId, Criterion,
3 };
4 use referencing::{Draft, Registry};
5 use serde_json::json;
6
7 fn bench_anchor_lookup(c: &mut Criterion) {
8 let data = json!({
9 "definitions": {
10 "foo": {
11 "id": "#foo",
12 "foo": "bar"
13 }
14 }
15 });
16 let resource = Draft::Draft4.create_resource(data);
17 let registry =
18 Registry::try_new("http://example.com/", resource).expect("Invalid registry input");
19
20 let mut group = c.benchmark_group("Anchor Lookup");
21
22 // Benchmark lookup of existing anchor
23 group.bench_with_input(
24 BenchmarkId::new("resolve", "small"),
25 &registry,
26 |b, registry| {
27 let resolver = registry
28 .try_resolver("http://example.com/")
29 .expect("Invalid base URI");
30 b.iter_with_large_drop(|| resolver.lookup(black_box("#foo")));
31 },
32 );
33
34 group.finish();
35 }
36
37 criterion_group!(benches, bench_anchor_lookup);
38 criterion_main!(benches);