Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions private/react-native-fantom/src/Benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,16 @@ export function suite(
bench.add(task.name, task.fn, options);
}

if (!isTestOnly) {
console.log(`Running benchmark: ${suiteName}. Please wait.`);
}

const runStartTime = performance.now();

bench.runSync();

if (!isTestOnly) {
printBenchmarkResults(bench);
printBenchmarkResults(bench, runStartTime);
}

for (const verify of verifyFns) {
Expand Down Expand Up @@ -262,16 +268,24 @@ export function suite(
return suiteAPI;
}

function printBenchmarkResults(bench: Bench) {
function printBenchmarkResults(bench: Bench, runStartTime: number) {
const {fantomConfigSummary} = getConstants();
const benchmarkName =
(bench.name ?? 'Benchmark') +
(fantomConfigSummary ? ` (${fantomConfigSummary})` : '');

const runDuration = performance.now() - runStartTime;
const durationStr =
runDuration < 1000
? `${runDuration.toFixed(0)}ms`
: `${(runDuration / 1000).toFixed(0)}s`;

console.log('');
console.log(`### ${benchmarkName} ###`);
console.table(nullthrows(bench.table()));
console.log('');
console.log(`Total benchmark duration: ${durationStr}`);
console.log('');
}

function createBenchmarkResultsObject(
Expand Down
Loading