mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
[ty] Add benchmark for union of tuples (#18076)
## Summary Add a micro-benchmark for the code pattern observed in https://github.com/astral-sh/ty/issues/362. This currently takes around 1 second on my machine. ## Test Plan ```bash cargo bench -p ruff_benchmark -- 'ty_micro\[many_tuple' --sample-size 10 ```
This commit is contained in:
parent
cfbb914100
commit
301d9985d8
1 changed files with 57 additions and 1 deletions
|
@ -301,6 +301,62 @@ fn benchmark_many_string_assignments(criterion: &mut Criterion) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn benchmark_many_tuple_assignments(criterion: &mut Criterion) {
|
||||||
|
setup_rayon();
|
||||||
|
|
||||||
|
criterion.bench_function("ty_micro[many_tuple_assignments]", |b| {
|
||||||
|
b.iter_batched_ref(
|
||||||
|
|| {
|
||||||
|
// This is a micro benchmark, but it is effectively identical to a code sample
|
||||||
|
// observed in https://github.com/astral-sh/ty/issues/362
|
||||||
|
setup_micro_case(
|
||||||
|
r#"
|
||||||
|
def flag() -> bool:
|
||||||
|
return True
|
||||||
|
|
||||||
|
t = ()
|
||||||
|
if flag():
|
||||||
|
t += (1,)
|
||||||
|
if flag():
|
||||||
|
t += (2,)
|
||||||
|
if flag():
|
||||||
|
t += (3,)
|
||||||
|
if flag():
|
||||||
|
t += (4,)
|
||||||
|
if flag():
|
||||||
|
t += (5,)
|
||||||
|
if flag():
|
||||||
|
t += (6,)
|
||||||
|
if flag():
|
||||||
|
t += (7,)
|
||||||
|
if flag():
|
||||||
|
t += (8,)
|
||||||
|
if flag():
|
||||||
|
t += (9,)
|
||||||
|
if flag():
|
||||||
|
t += (10,)
|
||||||
|
if flag():
|
||||||
|
t += (11,)
|
||||||
|
|
||||||
|
# Perform some kind of operation on the union type
|
||||||
|
print(1 in t)
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|case| {
|
||||||
|
let Case { db, .. } = case;
|
||||||
|
let result = db.check().unwrap();
|
||||||
|
assert_eq!(result.len(), 0);
|
||||||
|
},
|
||||||
|
BatchSize::SmallInput,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
criterion_group!(check_file, benchmark_cold, benchmark_incremental);
|
criterion_group!(check_file, benchmark_cold, benchmark_incremental);
|
||||||
criterion_group!(micro, benchmark_many_string_assignments);
|
criterion_group!(
|
||||||
|
micro,
|
||||||
|
benchmark_many_string_assignments,
|
||||||
|
benchmark_many_tuple_assignments
|
||||||
|
);
|
||||||
criterion_main!(check_file, micro);
|
criterion_main!(check_file, micro);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue