Skip to content

Commit

Permalink
feat: New torin benchmark for invalidations in the middle of the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Sep 24, 2023
1 parent 239c32c commit c27ab92
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions crates/torin/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,82 @@ fn criterion_benchmark(c: &mut Criterion) {
})
},
);

g.bench_function(
"big trees (deep + cached) + invalidated node in the middle",
|b| {
let mut layout = Torin::<usize>::new();
let mut measurer = Some(TestingMeasurer);
let mut mocked_dom = TestingDOM::default();

let children_ids = (1..=101).into_iter().collect::<Vec<usize>>();

let mut root = 0;

mocked_dom.add(
0,
None,
children_ids.clone(),
Node::from_size_and_direction(
Size::Percentage(Length::new(100.0)),
Size::Percentage(Length::new(100.0)),
DirectionMode::Vertical,
),
);

let levels = 20;

for level in 0..levels {
for i in &children_ids {
let id = (level * 1000) + *i;

mocked_dom.add(
id,
Some(root),
vec![],
Node::from_size_and_direction(
Size::Pixels(Length::new(100.0)),
Size::Pixels(Length::new(100.0)),
DirectionMode::Vertical,
),
);

if *i == 101 {
root = id
}
}
}

layout.find_best_root(&mut mocked_dom);
layout.measure(
0,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(1000.0, 1000.0)),
&mut measurer,
&mut mocked_dom,
);

b.iter(|| {
black_box({
mocked_dom.set_node(
1,
Node::from_size_and_direction(
Size::Inner,
Size::Pixels(Length::new(10.0)),
DirectionMode::Vertical,
),
);
layout.invalidate(1000);
layout.find_best_root(&mut mocked_dom);
layout.measure(
0,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(1000.0, 1000.0)),
&mut measurer,
&mut mocked_dom,
)
});
})
},
);
}

criterion_group!(benches, criterion_benchmark);
Expand Down

0 comments on commit c27ab92

Please sign in to comment.