2016-08-01 07:29:34 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
2016-12-02 11:18:12 -08:00
|
|
|
#include "YGBenchmark.h"
|
2016-08-01 07:29:34 -07:00
|
|
|
|
|
|
|
#include <CSSLayout/CSSLayout.h>
|
|
|
|
|
2016-10-31 10:31:50 -07:00
|
|
|
static CSSSize _measure(CSSNodeRef node,
|
2016-08-22 08:17:31 -07:00
|
|
|
float width,
|
2016-12-02 05:47:43 -08:00
|
|
|
YGMeasureMode widthMode,
|
2016-08-22 08:17:31 -07:00
|
|
|
float height,
|
2016-12-02 05:47:43 -08:00
|
|
|
YGMeasureMode heightMode) {
|
2016-08-15 09:15:02 -07:00
|
|
|
return (CSSSize){
|
2016-12-02 05:47:43 -08:00
|
|
|
.width = widthMode == YGMeasureModeUndefined ? 10 : width,
|
|
|
|
.height = heightMode == YGMeasureModeUndefined ? 10 : width,
|
2016-08-11 02:23:52 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-02 11:18:12 -08:00
|
|
|
YGBENCHMARKS({
|
2016-08-01 07:29:34 -07:00
|
|
|
|
2016-12-02 11:18:12 -08:00
|
|
|
YGBENCHMARK("Stack with flex", {
|
2016-08-22 06:58:13 -07:00
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-08-01 07:29:34 -07:00
|
|
|
CSSNodeStyleSetWidth(root, 100);
|
|
|
|
CSSNodeStyleSetHeight(root, 100);
|
|
|
|
|
2016-08-11 02:23:52 -07:00
|
|
|
for (uint32_t i = 0; i < 10; i++) {
|
2016-08-22 06:58:13 -07:00
|
|
|
const CSSNodeRef child = CSSNodeNew();
|
2016-08-11 02:23:52 -07:00
|
|
|
CSSNodeSetMeasureFunc(child, _measure);
|
|
|
|
CSSNodeStyleSetFlex(child, 1);
|
|
|
|
CSSNodeInsertChild(root, child, 0);
|
|
|
|
}
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-29 04:09:56 -07:00
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-11 02:23:52 -07:00
|
|
|
});
|
|
|
|
|
2016-12-02 11:18:12 -08:00
|
|
|
YGBENCHMARK("Align stretch in undefined axis", {
|
2016-08-22 06:58:13 -07:00
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-08-11 02:23:52 -07:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < 10; i++) {
|
2016-08-22 06:58:13 -07:00
|
|
|
const CSSNodeRef child = CSSNodeNew();
|
2016-08-01 07:29:34 -07:00
|
|
|
CSSNodeStyleSetHeight(child, 20);
|
2016-08-11 02:23:52 -07:00
|
|
|
CSSNodeSetMeasureFunc(child, _measure);
|
|
|
|
CSSNodeInsertChild(root, child, 0);
|
|
|
|
}
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-29 04:09:56 -07:00
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-11 02:23:52 -07:00
|
|
|
});
|
|
|
|
|
2016-12-02 11:18:12 -08:00
|
|
|
YGBENCHMARK("Nested flex", {
|
2016-08-22 06:58:13 -07:00
|
|
|
const CSSNodeRef root = CSSNodeNew();
|
2016-08-11 02:23:52 -07:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < 10; i++) {
|
2016-08-22 06:58:13 -07:00
|
|
|
const CSSNodeRef child = CSSNodeNew();
|
2016-08-01 07:29:34 -07:00
|
|
|
CSSNodeStyleSetFlex(child, 1);
|
|
|
|
CSSNodeInsertChild(root, child, 0);
|
2016-08-11 02:23:52 -07:00
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < 10; ii++) {
|
2016-08-22 06:58:13 -07:00
|
|
|
const CSSNodeRef grandChild = CSSNodeNew();
|
2016-08-11 02:23:52 -07:00
|
|
|
CSSNodeSetMeasureFunc(grandChild, _measure);
|
|
|
|
CSSNodeStyleSetFlex(grandChild, 1);
|
|
|
|
CSSNodeInsertChild(child, grandChild, 0);
|
|
|
|
}
|
2016-08-01 07:29:34 -07:00
|
|
|
}
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-09-29 04:09:56 -07:00
|
|
|
CSSNodeFreeRecursive(root);
|
2016-08-01 07:29:34 -07:00
|
|
|
});
|
|
|
|
|
2016-12-02 11:18:12 -08:00
|
|
|
YGBENCHMARK("Huge nested layout", {
|
2016-10-31 10:31:52 -07:00
|
|
|
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();
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetFlexDirection(grandChild, YGFlexDirectionRow);
|
2016-10-31 10:31:52 -07:00
|
|
|
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();
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeStyleSetFlexDirection(grandGrandGrandChild, YGFlexDirectionRow);
|
2016-10-31 10:31:52 -07:00
|
|
|
CSSNodeStyleSetFlexGrow(grandGrandGrandChild, 1);
|
|
|
|
CSSNodeStyleSetWidth(grandGrandGrandChild, 10);
|
|
|
|
CSSNodeStyleSetHeight(grandGrandGrandChild, 10);
|
|
|
|
CSSNodeInsertChild(grandGrandChild, grandGrandGrandChild, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
CSSNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
2016-10-31 10:31:52 -07:00
|
|
|
CSSNodeFreeRecursive(root);
|
|
|
|
});
|
|
|
|
|
2016-08-01 07:29:34 -07:00
|
|
|
});
|