2017-01-02 02:22:45 -08: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.
|
2018-01-19 11:25:26 -08:00
|
|
|
*
|
|
|
|
* @format
|
2017-01-02 02:22:45 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
require(`./tools`);
|
|
|
|
|
|
|
|
let fs = require(`fs`);
|
|
|
|
let vm = require(`vm`);
|
|
|
|
|
|
|
|
let WARMUP_ITERATIONS = 3;
|
|
|
|
let BENCHMARK_ITERATIONS = 10;
|
|
|
|
|
|
|
|
let 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
|
|
|
});
|
|
|
|
|
|
|
|
let testResults = new Map();
|
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
for (let type of [`node`, `browser`]) {
|
|
|
|
for (let file of testFiles) {
|
|
|
|
vm.runInNewContext(
|
|
|
|
file,
|
|
|
|
Object.assign(Object.create(global), {
|
|
|
|
Yoga: require(`../dist/entry-${type}`),
|
|
|
|
YGBENCHMARK: function(name, fn) {
|
|
|
|
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
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
let 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
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
let 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);
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2017-01-02 02:22:45 -08:00
|
|
|
}
|
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
console.log(
|
|
|
|
`Note: those tests are independants; there is no time relation to be expected between them`,
|
|
|
|
);
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
for (let [name, results] of testResults) {
|
|
|
|
console.log();
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
let 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
|
|
|
|
2018-01-19 11:25:26 -08:00
|
|
|
for (let [type, result] of results) {
|
|
|
|
console.log(
|
|
|
|
` - ${type}: ${result}ms (${Math.round(result / min * 10000) / 100}%)`,
|
|
|
|
);
|
|
|
|
}
|
2017-01-02 02:22:45 -08:00
|
|
|
}
|