2022-12-28 01:27:12 -08:00
|
|
|
#!/usr/bin/env node
|
2017-01-02 02:22:45 -08:00
|
|
|
/**
|
2022-10-04 13:59:32 -07:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2017-01-02 02:22:45 -08:00
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-01-19 11:25:26 -08:00
|
|
|
*
|
|
|
|
* @format
|
2017-01-02 02:22:45 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
require(`./tools`);
|
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
const fs = require(`fs`);
|
|
|
|
const vm = require(`vm`);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
const WARMUP_ITERATIONS = 3;
|
|
|
|
const BENCHMARK_ITERATIONS = 10;
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
const testFiles = process.argv.slice(2).map((file) => {
|
2018-01-19 11:25:26 -08:00
|
|
|
return fs.readFileSync(file).toString();
|
2017-01-02 02:22:45 -08:00
|
|
|
});
|
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
const testResults = new Map();
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
for (const type of ["asmjs", "wasm"]) {
|
|
|
|
for (const file of testFiles) {
|
2018-01-19 11:25:26 -08:00
|
|
|
vm.runInNewContext(
|
|
|
|
file,
|
|
|
|
Object.assign(Object.create(global), {
|
2022-12-28 01:27:12 -08:00
|
|
|
Yoga: require(type === "asmjs"
|
|
|
|
? "../dist/entrypoint/asmjs-sync"
|
|
|
|
: "../dist/entrypoint/wasm-sync"),
|
|
|
|
YGBENCHMARK: function (name, fn) {
|
2018-01-19 11:25:26 -08:00
|
|
|
let testEntry = testResults.get(name);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
if (testEntry === undefined)
|
|
|
|
testResults.set(name, (testEntry = new Map()));
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
for (let t = 0; t < WARMUP_ITERATIONS; ++t) fn();
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
const start = Date.now();
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
for (let t = 0; t < BENCHMARK_ITERATIONS; ++t) fn();
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
const end = Date.now();
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
testEntry.set(type, (end - start) / BENCHMARK_ITERATIONS);
|
|
|
|
},
|
2022-12-28 01:27:12 -08:00
|
|
|
})
|
2018-01-19 11:25:26 -08:00
|
|
|
);
|
|
|
|
}
|
2017-01-02 02:22:45 -08:00
|
|
|
}
|
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
console.log(
|
2022-12-28 01:27:12 -08:00
|
|
|
`Note: those tests are independants; there is no time relation to be expected between them`
|
2018-01-19 11:25:26 -08:00
|
|
|
);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
for (const [name, results] of testResults) {
|
2018-01-19 11:25:26 -08:00
|
|
|
console.log();
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
const min = Math.min(Infinity, ...results.values());
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
console.log(name);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
for (const [type, result] of results) {
|
2018-01-19 11:25:26 -08:00
|
|
|
console.log(
|
2022-12-28 01:27:12 -08:00
|
|
|
` - ${type}: ${result}ms (${Math.round((result / min) * 10000) / 100}%)`
|
2018-01-19 11:25:26 -08:00
|
|
|
);
|
|
|
|
}
|
2017-01-02 02:22:45 -08:00
|
|
|
}
|