Add benchmarks and change repetition count

Summary: The previous repetition count did not scale to many benchmarks. Also add more benchmarks

Reviewed By: adamjernst

Differential Revision: D3697280

fbshipit-source-id: 56fe424f36936445f31d6e9fa080abbdd816d32d
This commit is contained in:
Emil Sjolander
2016-08-11 02:23:52 -07:00
committed by Facebook Github Bot 0
parent 450472766d
commit 118f64f206
2 changed files with 49 additions and 4 deletions

View File

@@ -9,8 +9,20 @@
#include "CSSBenchmark.h"
#include <time.h>
#include <CSSLayout/CSSLayout.h>
// Measure functions can be quite slow, for example when measuring text.
// Simulate this by sleeping for 1 millisecond.
static CSSSize _measure(void *context, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) {
struct timespec sleeptime = {0, 1000000};
nanosleep(&sleeptime, NULL);
return (CSSSize) {
.width = widthMode == CSSMeasureModeUndefined ? 10 : width,
.height = heightMode == CSSMeasureModeUndefined ? 10 : width,
};
}
CSS_BENCHMARKS({
CSS_BENCHMARK("Stack with flex", {
@@ -18,14 +30,47 @@ CSS_BENCHMARKS({
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
for (uint32_t i = 0; i < 3; i++) {
for (uint32_t i = 0; i < 10; i++) {
CSSNodeRef child = CSSNodeNew();
CSSNodeStyleSetHeight(child, 20);
CSSNodeSetMeasureFunc(child, _measure);
CSSNodeStyleSetFlex(child, 1);
CSSNodeInsertChild(root, child, 0);
}
CSSNodeCalculateLayout(root, 100, 100, CSSDirectionLTR);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
});
CSS_BENCHMARK("Align stretch in undefined axis", {
CSSNodeRef root = CSSNodeNew();
for (uint32_t i = 0; i < 10; i++) {
CSSNodeRef child = CSSNodeNew();
CSSNodeStyleSetHeight(child, 20);
CSSNodeSetMeasureFunc(child, _measure);
CSSNodeInsertChild(root, child, 0);
}
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
});
CSS_BENCHMARK("Nested flex", {
CSSNodeRef root = CSSNodeNew();
for (uint32_t i = 0; i < 10; i++) {
CSSNodeRef child = CSSNodeNew();
CSSNodeSetMeasureFunc(child, _measure);
CSSNodeStyleSetFlex(child, 1);
CSSNodeInsertChild(root, child, 0);
for (uint32_t ii = 0; ii < 10; ii++) {
CSSNodeRef grandChild = CSSNodeNew();
CSSNodeSetMeasureFunc(grandChild, _measure);
CSSNodeStyleSetFlex(grandChild, 1);
CSSNodeInsertChild(child, grandChild, 0);
}
}
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
});
});

View File

@@ -14,7 +14,7 @@
#include <stdint.h>
#include <time.h>
#define NUM_REPETITIONS 100000
#define NUM_REPETITIONS 100
#define CSS_BENCHMARKS(BLOCK) \
int main(int argc, char const *argv[]) { \