gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5464Rust 87Markdown 12TOML 91903 Definiciones

⎇ 832e2da45631009be13279a06c30f09962db0688 benches/complex.rs Rust · 126 líneas · 4.4 KB Historia Quién tocó qué crudo

Cleanup `new_with_children()` uses (#194) 832e2da45 · Andreas Weibye ·

1use criterion::{criterion_group, criterion_main, Criterion};
2
3fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
4    let node111 = taffy
5        .new_leaf(taffy::style::FlexboxLayout {
6            size: taffy::geometry::Size {
7                width: taffy::style::Dimension::Points(10.0),
8                height: taffy::style::Dimension::Points(10.0),
9            },
10            ..Default::default()
11        })
12        .unwrap();
13    let node112 = taffy
14        .new_leaf(taffy::style::FlexboxLayout {
15            size: taffy::geometry::Size {
16                width: taffy::style::Dimension::Points(10.0),
17                height: taffy::style::Dimension::Points(10.0),
18            },
19            ..Default::default()
20        })
21        .unwrap();
22
23    let node121 = taffy
24        .new_leaf(taffy::style::FlexboxLayout {
25            size: taffy::geometry::Size {
26                width: taffy::style::Dimension::Points(10.0),
27                height: taffy::style::Dimension::Points(10.0),
28            },
29            ..Default::default()
30        })
31        .unwrap();
32    let node122 = taffy
33        .new_leaf(taffy::style::FlexboxLayout {
34            size: taffy::geometry::Size {
35                width: taffy::style::Dimension::Points(10.0),
36                height: taffy::style::Dimension::Points(10.0),
37            },
38            ..Default::default()
39        })
40        .unwrap();
41
42    let node11 =
43        taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node111, node112]).unwrap();
44    let node12 =
45        taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node121, node122]).unwrap();
46    let node1 =
47        taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node11, node12]).unwrap();
48
49    let node211 = taffy
50        .new_leaf(taffy::style::FlexboxLayout {
51            size: taffy::geometry::Size {
52                width: taffy::style::Dimension::Points(10.0),
53                height: taffy::style::Dimension::Points(10.0),
54            },
55            ..Default::default()
56        })
57        .unwrap();
58    let node212 = taffy
59        .new_leaf(taffy::style::FlexboxLayout {
60            size: taffy::geometry::Size {
61                width: taffy::style::Dimension::Points(10.0),
62                height: taffy::style::Dimension::Points(10.0),
63            },
64            ..Default::default()
65        })
66        .unwrap();
67
68    let node221 = taffy
69        .new_leaf(taffy::style::FlexboxLayout {
70            size: taffy::geometry::Size {
71                width: taffy::style::Dimension::Points(10.0),
72                height: taffy::style::Dimension::Points(10.0),
73            },
74            ..Default::default()
75        })
76        .unwrap();
77    let node222 = taffy
78        .new_leaf(taffy::style::FlexboxLayout {
79            size: taffy::geometry::Size {
80                width: taffy::style::Dimension::Points(10.0),
81                height: taffy::style::Dimension::Points(10.0),
82            },
83            ..Default::default()
84        })
85        .unwrap();
86
87    let node21 =
88        taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node211, node212]).unwrap();
89    let node22 =
90        taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node221, node222]).unwrap();
91
92    let node2 =
93        taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node21, node22]).unwrap();
94
95    taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node1, node2]).unwrap()
96}
97
98fn taffy_benchmarks(c: &mut Criterion) {
99    c.bench_function("deep hierarchy - build", |b| {
100        b.iter(|| {
101            let mut taffy = taffy::node::Taffy::new();
102            build_deep_hierarchy(&mut taffy);
103        })
104    });
105
106    c.bench_function("deep hierarchy - single", |b| {
107        b.iter(|| {
108            let mut taffy = taffy::node::Taffy::new();
109            let root = build_deep_hierarchy(&mut taffy);
110            taffy.compute_layout(root, taffy::geometry::Size::undefined()).unwrap()
111        })
112    });
113
114    c.bench_function("deep hierarchy - relayout", |b| {
115        let mut taffy = taffy::node::Taffy::new();
116        let root = build_deep_hierarchy(&mut taffy);
117
118        b.iter(|| {
119            taffy.mark_dirty(root).unwrap();
120            taffy.compute_layout(root, taffy::geometry::Size::undefined()).unwrap()
121        })
122    });
123}
124
125criterion_group!(benches, taffy_benchmarks);
126criterion_main!(benches);