Skip to content

Commit

Permalink
Use named function in incremental red knot benchmark (#14033)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Nov 1, 2024
1 parent cf0f5e1 commit 48fa839
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions crates/ruff_benchmark/benches/red_knot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,40 +120,42 @@ fn setup_rayon() {
}

fn benchmark_incremental(criterion: &mut Criterion) {
setup_rayon();
fn setup() -> Case {
let case = setup_case();
let result = case.db.check().unwrap();

criterion.bench_function("red_knot_check_file[incremental]", |b| {
b.iter_batched_ref(
|| {
let case = setup_case();
case.db.check().unwrap();

case.fs
.write_file(
&case.re_path,
format!("{}\n# A comment\n", source_text(&case.db, case.re).as_str()),
)
.unwrap();

case
},
|case| {
let Case { db, .. } = case;
assert_eq!(result, EXPECTED_DIAGNOSTICS);

db.apply_changes(
vec![ChangeEvent::Changed {
path: case.re_path.clone(),
kind: ChangedKind::FileContent,
}],
None,
);
case.fs
.write_file(
&case.re_path,
format!("{}\n# A comment\n", source_text(&case.db, case.re).as_str()),
)
.unwrap();

let result = db.check().unwrap();
case
}

assert_eq!(result, EXPECTED_DIAGNOSTICS);
},
BatchSize::SmallInput,
fn incremental(case: &mut Case) {
let Case { db, .. } = case;

db.apply_changes(
vec![ChangeEvent::Changed {
path: case.re_path.clone(),
kind: ChangedKind::FileContent,
}],
None,
);

let result = db.check().unwrap();

assert_eq!(result, EXPECTED_DIAGNOSTICS);
}

setup_rayon();

criterion.bench_function("red_knot_check_file[incremental]", |b| {
b.iter_batched_ref(setup, incremental, BatchSize::SmallInput);
});
}

Expand Down

0 comments on commit 48fa839

Please sign in to comment.