Files
yoga/javascript/tests/run-bench.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-12-23 00:43:57 -08:00
#!/usr/bin/env 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
*/
require(`./tools`);
let fs = require(`fs`);
let vm = require(`vm`);
let WARMUP_ITERATIONS = 3;
let BENCHMARK_ITERATIONS = 10;
2022-12-24 01:46:20 -08:00
let testFiles = process.argv.slice(2).map((file) => {
return fs.readFileSync(file).toString();
});
let testResults = new Map();
2022-12-24 01:46:20 -08:00
for (let type of ["asmjs", "wasm"]) {
for (let file of testFiles) {
vm.runInNewContext(
file,
Object.assign(Object.create(global), {
2022-12-24 01:46:20 -08:00
Yoga: require(type === "asmjs"
? "../dist/entrypoint/asmjs-sync"
: "../dist/entrypoint/wasm-sync"),
YGBENCHMARK: function (name, fn) {
let testEntry = testResults.get(name);
if (testEntry === undefined)
testResults.set(name, (testEntry = new Map()));
for (let t = 0; t < WARMUP_ITERATIONS; ++t) fn();
let start = Date.now();
for (let t = 0; t < BENCHMARK_ITERATIONS; ++t) fn();
let end = Date.now();
testEntry.set(type, (end - start) / BENCHMARK_ITERATIONS);
},
2022-12-24 01:46:20 -08:00
})
);
}
}
console.log(
2022-12-24 01:46:20 -08:00
`Note: those tests are independants; there is no time relation to be expected between them`
);
for (let [name, results] of testResults) {
console.log();
let min = Math.min(Infinity, ...results.values());
console.log(name);
for (let [type, result] of results) {
console.log(
2022-12-24 01:46:20 -08:00
` - ${type}: ${result}ms (${Math.round((result / min) * 10000) / 100}%)`
);
}
}