Skip to content

Commit c591299

Browse files
Add a nice chart to benchmarks
1 parent 860c362 commit c591299

File tree

3 files changed

+101
-6
lines changed

3 files changed

+101
-6
lines changed

packages/react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@powersync/web": "workspace:*",
3838
"@testing-library/react": "^15.0.2",
3939
"@types/react": "^18.3.1",
40+
"chart.js": "^4.5.0",
4041
"jsdom": "^24.0.0",
4142
"react": "18.3.1",
4243
"react-dom": "18.3.1",

packages/react/tests/profile.test.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as commonSdk from '@powersync/common';
22
import { PowerSyncDatabase } from '@powersync/web';
3+
import { Chart } from 'chart.js/auto';
34
import React, { Profiler } from 'react';
45
import ReactDOM from 'react-dom/client';
56
import { beforeEach, describe, it, Mock, onTestFinished, vi } from 'vitest';
@@ -420,5 +421,78 @@ describe.skipIf(skipTests)('Performance', { timeout: Infinity }, () => {
420421
totalResults.forEach((r) => {
421422
console.log(Object.values(r).join(','));
422423
});
424+
425+
// Make a nice chart, these are visible when running tests with a visible browser `headless: false`
426+
const chartCanvas = document.createElement('canvas');
427+
document.body.appendChild(chartCanvas);
428+
429+
// Chart the Average incremental render times
430+
const testTypes = new Set(Object.keys(totalResults[0]));
431+
// Don't show this on this chart
432+
testTypes.delete('differentialMemoImprovementPercentage');
433+
testTypes.delete('initialDataCount');
434+
new Chart(chartCanvas, {
435+
type: 'line',
436+
data: {
437+
labels: initialDataVolumeSteps,
438+
datasets: Array.from(testTypes).map((resultType) => {
439+
return {
440+
label: resultType,
441+
data: totalResults.map((r) => r[resultType])
442+
};
443+
})
444+
},
445+
options: {
446+
scales: {
447+
y: {
448+
beginAtZero: true,
449+
title: {
450+
display: true,
451+
text: 'Average incremental render time (ms)'
452+
}
453+
},
454+
x: {
455+
title: {
456+
display: true,
457+
text: 'Initial count of items'
458+
}
459+
}
460+
}
461+
}
462+
});
463+
464+
const percentCanvas = document.createElement('canvas');
465+
document.body.appendChild(percentCanvas);
466+
467+
// Chart the Average incremental render times
468+
new Chart(percentCanvas, {
469+
type: 'line',
470+
data: {
471+
labels: initialDataVolumeSteps,
472+
datasets: [
473+
{
474+
label: 'Percentage decrease of render time for Differential Memoized',
475+
data: totalResults.map((r) => r.differentialMemoImprovementPercentage)
476+
}
477+
]
478+
},
479+
options: {
480+
scales: {
481+
y: {
482+
beginAtZero: true,
483+
title: {
484+
display: true,
485+
text: 'Average incremental render time (ms)'
486+
}
487+
},
488+
x: {
489+
title: {
490+
display: true,
491+
text: 'Initial count of items'
492+
}
493+
}
494+
}
495+
}
496+
});
423497
});
424498
});

pnpm-lock.yaml

Lines changed: 26 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)