From df6368e048925d6441ba5a27eea4cf634aa364b8 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Mon, 31 Oct 2016 10:31:52 -0700 Subject: [PATCH] Add complex layout to benchmark Summary: Add a more complex benchmark which actually take a couple milliseconds to perform. This makes it easier to see if optimizations have any effect. More styles should be added later to make sure the benchmarks covers most of the csslayout code. Reviewed By: gkassabli Differential Revision: D4101780 fbshipit-source-id: 6bdf703edfbe64c47c77e04ef1ca946f4b75d093 --- benchmark/CSSBenchmark.c | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/benchmark/CSSBenchmark.c b/benchmark/CSSBenchmark.c index 6c1b831f..e08a1df7 100644 --- a/benchmark/CSSBenchmark.c +++ b/benchmark/CSSBenchmark.c @@ -75,4 +75,45 @@ CSS_BENCHMARKS({ CSSNodeFreeRecursive(root); }); + CSS_BENCHMARK("Huge nested layout", { + const CSSNodeRef root = CSSNodeNew(); + + for (uint32_t i = 0; i < 10; i++) { + const CSSNodeRef child = CSSNodeNew(); + CSSNodeStyleSetFlexGrow(child, 1); + CSSNodeStyleSetWidth(child, 10); + CSSNodeStyleSetHeight(child, 10); + CSSNodeInsertChild(root, child, 0); + + for (uint32_t ii = 0; ii < 10; ii++) { + const CSSNodeRef grandChild = CSSNodeNew(); + CSSNodeStyleSetFlexDirection(grandChild, CSSFlexDirectionRow); + CSSNodeStyleSetFlexGrow(grandChild, 1); + CSSNodeStyleSetWidth(grandChild, 10); + CSSNodeStyleSetHeight(grandChild, 10); + CSSNodeInsertChild(child, grandChild, 0); + + for (uint32_t iii = 0; iii < 10; iii++) { + const CSSNodeRef grandGrandChild = CSSNodeNew(); + CSSNodeStyleSetFlexGrow(grandGrandChild, 1); + CSSNodeStyleSetWidth(grandGrandChild, 10); + CSSNodeStyleSetHeight(grandGrandChild, 10); + CSSNodeInsertChild(grandChild, grandGrandChild, 0); + + for (uint32_t iii = 0; iii < 10; iii++) { + const CSSNodeRef grandGrandGrandChild = CSSNodeNew(); + CSSNodeStyleSetFlexDirection(grandGrandGrandChild, CSSFlexDirectionRow); + CSSNodeStyleSetFlexGrow(grandGrandGrandChild, 1); + CSSNodeStyleSetWidth(grandGrandGrandChild, 10); + CSSNodeStyleSetHeight(grandGrandGrandChild, 10); + CSSNodeInsertChild(grandGrandChild, grandGrandGrandChild, 0); + } + } + } + } + + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); + CSSNodeFreeRecursive(root); + }); + });