mirror of
https://github.com/hanzoai/yoga.git
synced 2026-10-30 19:34:29 +00:00
Summary: X-link: https://github.com/facebook/react-native/pull/56396 - "Wwhether" -> "Whether" in YGNode.h - "independants" -> "independent" in run-bench.ts Pull Request resolved: https://github.com/facebook/yoga/pull/1925 Reviewed By: cortinico Differential Revision: D100143075 Pulled By: fabriziocucci fbshipit-source-id: 1b20d0010bf9265d95be194613f6962ff31a4ba9
61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
#!/usr/bin/env ts-node
|
|
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import path from 'path';
|
|
|
|
const WARMUP_ITERATIONS = 3;
|
|
const BENCHMARK_ITERATIONS = 10;
|
|
|
|
const testFiles = process.argv.slice(2);
|
|
|
|
const testResults = new Map<string, Map<string, number>>();
|
|
|
|
for (const type of ['wasm']) {
|
|
for (const file of testFiles) {
|
|
globalThis.YGBENCHMARK = (name: string, fn: () => void) => {
|
|
let testEntry = testResults.get(name);
|
|
|
|
if (testEntry === undefined)
|
|
testResults.set(name, (testEntry = new Map()));
|
|
|
|
for (let t = 0; t < WARMUP_ITERATIONS; ++t) fn();
|
|
|
|
const start = Date.now();
|
|
|
|
for (let t = 0; t < BENCHMARK_ITERATIONS; ++t) fn();
|
|
|
|
const end = Date.now();
|
|
|
|
testEntry.set(type, (end - start) / BENCHMARK_ITERATIONS);
|
|
};
|
|
|
|
const modulePath = path.resolve(file);
|
|
await import(modulePath);
|
|
}
|
|
}
|
|
|
|
console.log(
|
|
`Note: those tests are independent; there is no time relation to be expected between them`,
|
|
);
|
|
|
|
for (const [name, results] of testResults) {
|
|
console.log();
|
|
|
|
const min = Math.min(Infinity, ...results.values());
|
|
|
|
console.log(name);
|
|
|
|
for (const [type, result] of results) {
|
|
console.log(
|
|
` - ${type}: ${result}ms (${Math.round((result / min) * 10000) / 100}%)`,
|
|
);
|
|
}
|
|
}
|