|
1 | 1 | import * as commonSdk from '@powersync/common'; |
2 | 2 | import { PowerSyncDatabase } from '@powersync/web'; |
| 3 | +import { Chart } from 'chart.js/auto'; |
3 | 4 | import React, { Profiler } from 'react'; |
4 | 5 | import ReactDOM from 'react-dom/client'; |
5 | 6 | import { beforeEach, describe, it, Mock, onTestFinished, vi } from 'vitest'; |
@@ -420,5 +421,78 @@ describe.skipIf(skipTests)('Performance', { timeout: Infinity }, () => { |
420 | 421 | totalResults.forEach((r) => { |
421 | 422 | console.log(Object.values(r).join(',')); |
422 | 423 | }); |
| 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 | + }); |
423 | 497 | }); |
424 | 498 | }); |
0 commit comments