Skip to content

Commit

Permalink
Merge pull request #4 from nvzqz/patch-1
Browse files Browse the repository at this point in the history
Improve use of Divan
  • Loading branch information
remi-dupre authored Mar 2, 2024
2 parents 83d58d6 + f6dee9e commit 6f7dc0f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions benches/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,36 @@ fn load_example(example: &str) -> Vec<String> {
.collect()
}

// Register a `fibonacci` function and benchmark it over multiple cases.
#[divan::bench(args = ["nix-shell.rec", "nixos-rebuild.rec"])]
fn parse_raw(bencher: Bencher, example: &str) {
let example = load_example(example);
let lines = load_example(example);

bencher
.with_inputs(|| &example)
.counter(divan::counter::ItemsCount::new(example.len()))
.bench_refs(|lines| {
.counter(lines.len())
.bench(|| {
lines
.iter()
.inspect(|line| {
let _: RawAction = serde_json::from_str(line).expect("invalid line");
let action: RawAction = serde_json::from_str(line).expect("invalid line");
divan::black_box_drop(action);
})
.count()
})
}

#[divan::bench(args = ["nix-shell.rec", "nixos-rebuild.rec"])]
fn parse(bencher: Bencher, example: &str) {
let example = load_example(example);
let lines = load_example(example);

bencher
.with_inputs(|| &example)
.counter(divan::counter::ItemsCount::new(example.len()))
.bench_refs(|lines| {
.counter(lines.len())
.bench(|| {
lines
.iter()
.inspect(|line| {
let raw: RawAction = serde_json::from_str(line).expect("invalid line");
let _: Action = raw.try_into().unwrap();
let action: Action = raw.try_into().unwrap();
divan::black_box_drop(action);
})
.count()
})
Expand Down

0 comments on commit 6f7dc0f

Please sign in to comment.