MCPcopy Create free account
hub / github.com/Snapchat/Valdi / createElementTree

Function createElementTree

valdi/test/benchmark/ViewNode_benchmark.cpp:137–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137static Element createElementTree() {
138 auto header =
139 Element("view")
140 .attribute("width", "100%")
141 .attribute("height", 200)
142 .attribute("backgroundColor", "white")
143 .child(Element("view")
144 .attribute("margin", 16)
145 .attribute("backgroundColor", "lightgray")
146 .attribute("flexGrow", 1)
147 .attribute("borderRadius", 16)
148 .attribute("borderColor", "yellow")
149 .child(Element("label").attribute("value", "Header").attribute("textAlign", "center")));
150
151 std::vector<Element> cards;
152 for (size_t i = 0; i < 100; i++) {
153 auto card = Element("view")
154 .attribute("width", 40)
155 .attribute("height", "100%")
156 .attribute("background", "white")
157 .child(Element("label")
158 .attribute("value", STRING_LITERAL("Hello world what is up"))
159 .attribute("lineSpacing", 4)
160 .attribute("font", "Title")
161 .attribute("fontSize", 16)
162 .attribute("color", "black")
163 .attribute("textAlign", "center")
164 .attribute("numberOfLines", 0)
165 .attribute("marginTop", 8)
166 .attribute("marginBottom", 16));
167
168 cards.emplace_back(std::move(card));
169 }
170
171 std::vector<Element> cells;
172 for (size_t i = 0; i < 20; i++) {
173 cells.emplace_back(Element("view")
174 .attribute("flexGrow", 1)
175 .child(Element("scroll").attribute("horizontal", true).setChildren(cards)));
176 }
177
178 auto root = Element("view")
179 .attribute("width", 100)
180 .attribute("height", 100)
181 .child(header)
182 .child(Element("scroll").attribute("flexGrow", 1).setChildren(cells));
183 return root;
184}
185
186static void InitialRender(benchmark::State& state) {
187 Dependencies deps;

Callers 2

InitialRenderFunction · 0.85
DestroyTreeFunction · 0.85

Calls 3

setChildrenMethod · 0.80
ElementClass · 0.70
childMethod · 0.45

Tested by

no test coverage detected