Skip to content

Commit 560aca0

Browse files
authored
[ty] Minor simplifications to some benchmark code (#24209)
1 parent 683bae5 commit 560aca0

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

  • crates/ruff_benchmark/benches

‎crates/ruff_benchmark/benches/ty.rs‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,13 @@ fn benchmark_many_enum_members(criterion: &mut Criterion) {
570570

571571
setup_rayon();
572572

573-
let mut code = String::new();
574-
writeln!(&mut code, "from enum import Enum").ok();
573+
let mut code = "from enum import Enum\n".to_string();
575574

576-
writeln!(&mut code, "class E(Enum):").ok();
575+
code.push_str("class E(Enum):\n");
577576
for i in 0..NUM_ENUM_MEMBERS {
578577
writeln!(&mut code, " m{i} = {i}").ok();
579578
}
580-
writeln!(&mut code).ok();
579+
code.push('\n');
581580

582581
code.push_str("print((");
583582
for i in 0..NUM_ENUM_MEMBERS {
@@ -674,13 +673,11 @@ class E(Enum):
674673
.ok();
675674
}
676675

677-
write!(
678-
&mut code,
676+
code.push_str(
679677
"
680678
case _:
681-
assert_never(self)"
682-
)
683-
.ok();
679+
assert_never(self)",
680+
);
684681

685682
criterion.bench_function("ty_micro[many_enum_members_2]", |b| {
686683
b.iter_batched_ref(
@@ -784,21 +781,20 @@ fn benchmark_large_isinstance_narrowing(criterion: &mut Criterion) {
784781

785782
setup_rayon();
786783

787-
let mut code = String::new();
788-
writeln!(&mut code, "class Base: ...").ok();
784+
let mut code = "class Base: ...\n".to_string();
789785
for i in 0..NUM_CLASSES {
790786
writeln!(&mut code, "class C{i}(Base): ...").ok();
791787
}
792-
writeln!(&mut code).ok();
788+
code.push('\n');
793789

794-
writeln!(&mut code, "def f(obj: Base) -> None:").ok();
790+
code.push_str("def f(obj: Base) -> None:\n");
795791
for i in 0..NUM_CLASSES {
796792
if i == 0 {
797793
writeln!(&mut code, " if isinstance(obj, C{i}):").ok();
798794
} else {
799795
writeln!(&mut code, " elif isinstance(obj, C{i}):").ok();
800796
}
801-
writeln!(&mut code, " pass").ok();
797+
code.push_str(" pass\n");
802798
}
803799

804800
criterion.bench_function("ty_micro[large_isinstance_narrowing]", |b| {

0 commit comments

Comments
 (0)