⎇ a380b58cb0418ea3728af9a67d188410c6c10f7a
benches/complex.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Update all benchmarks to use the new API
1use criterion::{criterion_group, criterion_main, Criterion};
2
3fn build_deep_hierarchy(stretch: &mut stretch::node::Stretch) -> stretch::node::Node {
4 let node111 = stretch
5 .new_node(
6 stretch::style::Style {
7 size: stretch::geometry::Size {
8 width: stretch::style::Dimension::Points(10.0),
9 height: stretch::style::Dimension::Points(10.0),
10 },
11 ..Default::default()
12 },
13 &[],
14 )
15 .unwrap();
16 let node112 = stretch
17 .new_node(
18 stretch::style::Style {
19 size: stretch::geometry::Size {
20 width: stretch::style::Dimension::Points(10.0),
21 height: stretch::style::Dimension::Points(10.0),
22 },
23 ..Default::default()
24 },
25 &[],
26 )
27 .unwrap();
28
29 let node121 = stretch
30 .new_node(
31 stretch::style::Style {
32 size: stretch::geometry::Size {
33 width: stretch::style::Dimension::Points(10.0),
34 height: stretch::style::Dimension::Points(10.0),
35 },
36 ..Default::default()
37 },
38 &[],
39 )
40 .unwrap();
41 let node122 = stretch
42 .new_node(
43 stretch::style::Style {
44 size: stretch::geometry::Size {
45 width: stretch::style::Dimension::Points(10.0),
46 height: stretch::style::Dimension::Points(10.0),
47 },
48 ..Default::default()
49 },
50 &[],
51 )
52 .unwrap();
53
54 let node11 = stretch.new_node(stretch::style::Style { ..Default::default() }, &[node111, node112]).unwrap();
55 let node12 = stretch.new_node(stretch::style::Style { ..Default::default() }, &[node121, node122]).unwrap();
56 let node1 = stretch.new_node(stretch::style::Style { ..Default::default() }, &[node11, node12]).unwrap();
57
58 let node211 = stretch
59 .new_node(
60 stretch::style::Style {
61 size: stretch::geometry::Size {
62 width: stretch::style::Dimension::Points(10.0),
63 height: stretch::style::Dimension::Points(10.0),
64 },
65 ..Default::default()
66 },
67 &[],
68 )
69 .unwrap();
70 let node212 = stretch
71 .new_node(
72 stretch::style::Style {
73 size: stretch::geometry::Size {
74 width: stretch::style::Dimension::Points(10.0),
75 height: stretch::style::Dimension::Points(10.0),
76 },
77 ..Default::default()
78 },
79 &[],
80 )
81 .unwrap();
82
83 let node221 = stretch
84 .new_node(
85 stretch::style::Style {
86 size: stretch::geometry::Size {
87 width: stretch::style::Dimension::Points(10.0),
88 height: stretch::style::Dimension::Points(10.0),
89 },
90 ..Default::default()
91 },
92 &[],
93 )
94 .unwrap();
95 let node222 = stretch
96 .new_node(
97 stretch::style::Style {
98 size: stretch::geometry::Size {
99 width: stretch::style::Dimension::Points(10.0),
100 height: stretch::style::Dimension::Points(10.0),
101 },
102 ..Default::default()
103 },
104 &[],
105 )
106 .unwrap();
107
108 let node21 = stretch.new_node(stretch::style::Style { ..Default::default() }, &[node211, node212]).unwrap();
109 let node22 = stretch.new_node(stretch::style::Style { ..Default::default() }, &[node221, node222]).unwrap();
110
111 let node2 = stretch.new_node(stretch::style::Style { ..Default::default() }, &[node21, node22]).unwrap();
112 let node0 = stretch.new_node(stretch::style::Style { ..Default::default() }, &[node1, node2]).unwrap();
113
114 node0
115}
116
117fn stretch_benchmarks(c: &mut Criterion) {
118 c.bench_function("deep hierarchy - build", |b| {
119 b.iter(|| {
120 let mut stretch = stretch::node::Stretch::new();
121 build_deep_hierarchy(&mut stretch);
122 })
123 });
124
125 c.bench_function("deep hierarchy - single", |b| {
126 b.iter(|| {
127 let mut stretch = stretch::node::Stretch::new();
128 let root = build_deep_hierarchy(&mut stretch);
129 stretch.compute_layout(root, stretch::geometry::Size::undefined()).unwrap()
130 })
131 });
132
133 c.bench_function("deep hierarchy - relayout", |b| {
134 let mut stretch = stretch::node::Stretch::new();
135 let root = build_deep_hierarchy(&mut stretch);
136
137 b.iter(|| {
138 stretch.mark_dirty(root).unwrap();
139 stretch.compute_layout(root, stretch::geometry::Size::undefined()).unwrap()
140 })
141 });
142}
143
144criterion_group!(benches, stretch_benchmarks);
145criterion_main!(benches);