mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
641a79dc51
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53221 # Changelog: [Internal] - This changes the benchmark test results comparison print the results slightly differently, in particular it now uses the slowest result as a baseline and prints how much faster the other ones are (as opposed to printing "slower" previously). This arguably brings a more positive vibe when looking into the benchmark results :) Reviewed By: andrewdacenko Differential Revision: D80082134 fbshipit-source-id: 7dc9c7c520afe08270d4f5da9031db02261690ba
85 lines
2.4 KiB
JavaScript
85 lines
2.4 KiB
JavaScript
/**
|
|
* 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.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
import type {BenchmarkResult} from '../src/Benchmark';
|
|
|
|
import {markdownTable} from './utils';
|
|
|
|
export const printBenchmarkResultsRanking = (
|
|
benchmarkResults: Array<{
|
|
title: string,
|
|
result: BenchmarkResult,
|
|
}>,
|
|
) => {
|
|
const testTaskTimings: {[string]: {[string]: number}} = {};
|
|
let numTestVariants = 0;
|
|
|
|
for (const benchmarkResult of benchmarkResults) {
|
|
const result = benchmarkResult.result;
|
|
if (
|
|
result == null ||
|
|
result.timings == null ||
|
|
benchmarkResult.title == null
|
|
) {
|
|
continue;
|
|
}
|
|
numTestVariants++;
|
|
for (const taskTiming of result.timings) {
|
|
const taskName = taskTiming.name;
|
|
if (testTaskTimings[taskName] === undefined) {
|
|
testTaskTimings[taskName] = {};
|
|
}
|
|
testTaskTimings[taskName][benchmarkResult.title] =
|
|
taskTiming.latency?.p50 ?? taskTiming.latency.mean;
|
|
}
|
|
}
|
|
if (numTestVariants <= 1 || Object.keys(testTaskTimings).length === 0) {
|
|
// No benchmark results to print, or there is nothing to compare with
|
|
return;
|
|
}
|
|
|
|
// Find relative execution times for tasks
|
|
const results: {[string]: {[string]: string}} = {};
|
|
for (const taskName in testTaskTimings) {
|
|
const kv = Object.entries(testTaskTimings[taskName]);
|
|
kv.sort((a, b) => b[1] - a[1]);
|
|
const slowest = kv[0][1];
|
|
const fastest = kv[kv.length - 1][1];
|
|
results[taskName] = {};
|
|
for (let i = 0; i < kv.length; i++) {
|
|
const [title, timing] = kv[i];
|
|
let caption =
|
|
timing === fastest ? '🏆 ' : timing === slowest ? '🐌 ' : '';
|
|
caption += `${timing.toFixed(3)}ms`;
|
|
caption += getTimingDelta(slowest, timing);
|
|
results[taskName][title] = caption;
|
|
}
|
|
}
|
|
|
|
console.log('### Benchmark Times Comparison (p50): ###');
|
|
console.log(markdownTable(results, 'Task name'));
|
|
console.log('');
|
|
};
|
|
|
|
function getTimingDelta(lastTiming: ?number, currentTiming: ?number): string {
|
|
if (
|
|
lastTiming != null &&
|
|
currentTiming != null &&
|
|
lastTiming !== currentTiming
|
|
) {
|
|
const delta = currentTiming - lastTiming;
|
|
const deltaPercent =
|
|
Math.abs(delta / (delta > 0 ? lastTiming : currentTiming)) * 100;
|
|
return ` (${deltaPercent.toFixed(2)}% ${delta > 0 ? 'slower' : 'faster'})`;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|