File: anchor.rs

package info (click to toggle)
rust-referencing 0.37.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 468 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use codspeed_criterion_compat::{
    black_box, criterion_group, criterion_main, BenchmarkId, Criterion,
};
use referencing::{Draft, Registry};
use serde_json::json;

fn bench_anchor_lookup(c: &mut Criterion) {
    let data = json!({
      "definitions": {
        "foo": {
          "id": "#foo",
          "foo": "bar"
        }
      }
    });
    let resource = Draft::Draft4.create_resource(data);
    let registry =
        Registry::try_new("http://example.com/", resource).expect("Invalid registry input");

    let mut group = c.benchmark_group("Anchor Lookup");

    // Benchmark lookup of existing anchor
    group.bench_with_input(
        BenchmarkId::new("resolve", "small"),
        &registry,
        |b, registry| {
            let resolver = registry
                .try_resolver("http://example.com/")
                .expect("Invalid base URI");
            b.iter_with_large_drop(|| resolver.lookup(black_box("#foo")));
        },
    );

    group.finish();
}

criterion_group!(benches, bench_anchor_lookup);
criterion_main!(benches);