-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
1313 lines (1125 loc) · 39.8 KB
/
test.html
File metadata and controls
1313 lines (1125 loc) · 39.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Framework Performance Benchmark</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
color: #333;
background-color: #f5f5f5;
}
h1,
h2 {
color: #2c3e50;
}
.control-panel {
background-color: #fff;
border-radius: 5px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
button {
background-color: #3498db;
color: white;
border: none;
padding: 10px 15px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin-right: 10px;
transition: background-color 0.3s;
}
button:hover {
background-color: #2980b9;
}
button:disabled {
background-color: #95a5a6;
cursor: not-allowed;
}
.framework-container {
display: none;
background-color: #fff;
padding: 20px;
border-radius: 5px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
overflow: auto;
height: 400px;
}
.results-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.results-table th,
.results-table td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
.results-table th {
background-color: #3498db;
color: white;
}
.results-table tr:nth-child(even) {
background-color: #f2f2f2;
}
.results-table tr:hover {
background-color: #e3f2fd;
}
.data-table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
.data-table th,
.data-table td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
.data-table th {
background-color: #f2f2f2;
position: sticky;
top: 0;
}
.data-table tr:nth-child(even) {
background-color: #f9f9f9;
}
.log-container {
background-color: #2c3e50;
color: #ecf0f1;
padding: 15px;
border-radius: 5px;
margin-top: 20px;
font-family: monospace;
max-height: 200px;
overflow-y: auto;
}
.log-entry {
margin: 5px 0;
border-bottom: 1px solid #34495e;
padding-bottom: 5px;
}
.chart-container {
height: 400px;
margin-top: 20px;
}
.loading {
text-align: center;
padding: 20px;
font-style: italic;
color: #7f8c8d;
}
.fastest {
color: #27ae60;
font-weight: bold;
}
.slowest {
color: #c0392b;
font-weight: bold;
}
.tab-container {
margin-top: 20px;
}
.tab-buttons {
display: flex;
margin-bottom: -1px;
}
.tab-button {
padding: 10px 20px;
background-color: #ecf0f1;
border: 1px solid #bdc3c7;
border-bottom: none;
border-radius: 5px 5px 0 0;
cursor: pointer;
margin-right: 5px;
}
.tab-button.active {
background-color: #fff;
border-bottom: 1px solid #fff;
}
.tab-content {
border: 1px solid #bdc3c7;
padding: 20px;
background-color: #fff;
border-radius: 0 5px 5px 5px;
}
.tab-panel {
display: none;
}
.tab-panel.active {
display: block;
}
.progress-container {
width: 100%;
height: 20px;
background-color: #ecf0f1;
border-radius: 10px;
margin: 20px 0;
overflow: hidden;
}
.progress-bar {
height: 100%;
background-color: #3498db;
width: 0%;
transition: width 0.3s ease;
}
</style>
</head>
<body>
<h1>Framework Performance Benchmark</h1>
<div class="control-panel">
<h2>Test Controls</h2>
<button id="generateDataBtn">1. Generate Test Data</button>
<button id="runAllTestsBtn" disabled>2. Run All Tests</button>
<button id="clearResultsBtn" disabled>Clear Results</button>
<div class="progress-container">
<div id="progressBar" class="progress-bar"></div>
</div>
<div>
<label for="rowCount">Row Count:</label>
<input type="number" id="rowCount" value="1000" min="100" max="10000">
<label for="colCount">Column Count:</label>
<input type="number" id="colCount" value="10" min="5" max="20">
<label for="iterations">Test Iterations:</label>
<input type="number" id="iterations" value="3" min="1" max="10">
</div>
</div>
<div class="tab-container">
<div class="tab-buttons">
<div class="tab-button active" data-tab="results">Results</div>
<div class="tab-button" data-tab="log">Log</div>
<div class="tab-button" data-tab="chart">Chart</div>
<div class="tab-button" data-tab="data">Test Data</div>
</div>
<div class="tab-content">
<div class="tab-panel active" id="results-panel">
<table class="results-table" id="resultsTable">
<thead>
<tr>
<th>Framework</th>
<th>Initial Render (ms)</th>
<th>Update All (ms)</th>
<th>Sort (ms)</th>
<th>Filter (ms)</th>
<th>Memory Increase (MB)</th>
<th>Status</th>
</tr>
</thead>
<tbody id="resultsBody">
<tr>
<td>LightBind</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>Pending</td>
</tr>
<tr>
<td>AngularJS</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>Pending</td>
</tr>
<tr>
<td>Vue.js</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>Pending</td>
</tr>
<tr>
<td>React</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>Pending</td>
</tr>
</tbody>
</table>
</div>
<div class="tab-panel" id="log-panel">
<div class="log-container" id="logContainer">
<div class="log-entry">Benchmark log will appear here...</div>
</div>
</div>
<div class="tab-panel" id="chart-panel">
<div class="chart-container">
<canvas id="resultsChart"></canvas>
</div>
</div>
<div class="tab-panel" id="data-panel">
<h3>Sample of Test Data</h3>
<div id="sampleDataContainer">
<p class="loading">Generate test data first...</p>
</div>
</div>
</div>
</div>
<div id="frameworkContainers">
<!-- LightBind -->
<div id="lightbind-container" class="framework-container">
<h2>LightBind Table</h2>
<div id="lightBindTableComponent">
<table class="data-table">
<thead>
<tr>
<th bind-repeat="col in columns">{{col.name}}</th>
</tr>
</thead>
<tbody>
<tr bind-repeat="row in rows" bind-class="'row-' + ($index % 2 === 0 ? 'even' : 'odd')">
<td bind-repeat="(key, value) in row">{{value}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- AngularJS -->
<div id="angularjs-container" class="framework-container" ng-app="benchmarkApp" ng-controller="AngularJSController">
<h2>AngularJS Table</h2>
<table class="data-table">
<thead>
<tr>
<th ng-repeat="col in columns">{{col.name}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rows" ng-class="'row-' + ($index % 2 === 0 ? 'even' : 'odd')">
<td ng-repeat="(key, value) in row">{{value}}</td>
</tr>
</tbody>
</table>
</div>
<!-- Vue.js -->
<div id="vue-container" class="framework-container">
<h2>Vue.js Table</h2>
<div id="vue-app">
<table class="data-table">
<thead>
<tr>
<th v-for="col in columns" :key="col.id">{{ col.name }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in rows" :key="row.id" :class="'row-' + (index % 2 === 0 ? 'even' : 'odd')">
<td v-for="(value, key) in row" :key="key">{{ value }}</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- React -->
<div id="react-container" class="framework-container">
<h2>React Table</h2>
<div id="react-app"></div>
</div>
</div>
<!-- Load Framework Libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.prod.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
<!-- Initialize AngularJS module -->
<script>
// Define the Angular module first, before any initialization happens
angular.module('benchmarkApp', [])
.controller('AngularJSController', function ($scope) {
$scope.columns = [];
$scope.rows = [];
});
</script>
<!-- LightBind Library (Include your files) -->
<script type="module">
import { LightBind } from './lightbind.js';
let lightBind = new LightBind();
lightBind.setGlobals();
window.lightBind = lightBind; // Make LightBind globally accessible
lightBind.start();
</script>
<!-- Benchmark Script -->
<script>
// Global variables
let testData = null;
let testColumns = null;
let chart = null;
let currentFrameworkIndex = 0;
let results = {
'LightBind': { render: [], update: [], sort: [], filter: [], memory: [] },
'AngularJS': { render: [], update: [], sort: [], filter: [], memory: [] },
'Vue.js': { render: [], update: [], sort: [], filter: [], memory: [] },
'React': { render: [], update: [], sort: [], filter: [], memory: [] }
};
let iterationCount = 3;
let currentIteration = 0;
// Helper function to measure performance
async function measurePerformance(framework, operationType, operationCallback) {
const startTime = performance.now();
await operationCallback(); // Execute the operation
// Wait for operation to complete with appropriate delay
const delay = operationType === 'render' ? 100 : 50;
await new Promise(resolve => setTimeout(resolve, delay));
const endTime = performance.now();
const elapsedTime = endTime - startTime;
// Record the result
results[framework][operationType].push(elapsedTime);
// Log the result
logMessage(`${framework} ${operationType}: ${elapsedTime.toFixed(2)}ms`);
return elapsedTime;
}
// Initialization
document.addEventListener('DOMContentLoaded', () => {
// Set up tabs
document.querySelectorAll('.tab-button').forEach(button => {
button.addEventListener('click', () => {
const tabId = button.getAttribute('data-tab');
// Update active tab button
document.querySelectorAll('.tab-button').forEach(btn => {
btn.classList.remove('active');
});
button.classList.add('active');
// Update active tab panel
document.querySelectorAll('.tab-panel').forEach(panel => {
panel.classList.remove('active');
});
document.getElementById(`${tabId}-panel`).classList.add('active');
// Update chart if showing chart tab
if (tabId === 'chart' && chart) {
chart.update();
}
});
});
// Set up button event listeners
document.getElementById('generateDataBtn').addEventListener('click', generateTestData);
document.getElementById('runAllTestsBtn').addEventListener('click', startTests);
document.getElementById('clearResultsBtn').addEventListener('click', clearResults);
// Log initial message
logMessage('Benchmark initialized. Click "Generate Test Data" to begin.');
});
function logMessage(message) {
const logContainer = document.getElementById('logContainer');
const logEntry = document.createElement('div');
logEntry.className = 'log-entry';
logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
logContainer.appendChild(logEntry);
logContainer.scrollTop = logContainer.scrollHeight;
}
function updateProgress(percent) {
document.getElementById('progressBar').style.width = `${percent}%`;
}
function generateTestData() {
const startTime = performance.now();
logMessage('Generating test data...');
const rowCount = parseInt(document.getElementById('rowCount').value, 10);
const colCount = parseInt(document.getElementById('colCount').value, 10);
iterationCount = parseInt(document.getElementById('iterations').value, 10);
// Generate column definitions
testColumns = [];
for (let i = 0; i < colCount; i++) {
testColumns.push({
id: `col${i}`,
name: `Column ${i + 1}`,
field: `field${i}`
});
}
// Generate row data
testData = [];
for (let i = 0; i < rowCount; i++) {
const row = { id: i };
for (let j = 0; j < colCount; j++) {
if (j === 0) {
row[`field${j}`] = `Item ${i}`;
} else if (j === 1) {
row[`field${j}`] = Math.floor(Math.random() * 1000);
} else if (j === 2) {
row[`field${j}`] = Math.random().toFixed(2);
} else if (j === 3) {
const date = new Date();
date.setDate(date.getDate() - Math.floor(Math.random() * 365));
row[`field${j}`] = date.toLocaleDateString();
} else {
row[`field${j}`] = `Value ${i}-${j}`;
}
}
testData.push(row);
}
// Show sample of data
const sampleContainer = document.getElementById('sampleDataContainer');
sampleContainer.innerHTML = '';
const table = document.createElement('table');
table.className = 'data-table';
// Create header
const thead = document.createElement('thead');
const headerRow = document.createElement('tr');
testColumns.forEach(col => {
const th = document.createElement('th');
th.textContent = col.name;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
table.appendChild(thead);
// Create sample rows (first 10)
const tbody = document.createElement('tbody');
const sampleSize = Math.min(10, testData.length);
for (let i = 0; i < sampleSize; i++) {
const tr = document.createElement('tr');
const row = testData[i];
testColumns.forEach(col => {
const td = document.createElement('td');
td.textContent = row[col.field];
tr.appendChild(td);
});
tbody.appendChild(tr);
}
table.appendChild(tbody);
sampleContainer.appendChild(table);
if (testData.length > sampleSize) {
const note = document.createElement('p');
note.textContent = `... and ${testData.length - sampleSize} more rows`;
sampleContainer.appendChild(note);
}
const endTime = performance.now();
logMessage(`Test data generated: ${rowCount} rows × ${colCount} columns in ${(endTime - startTime).toFixed(2)}ms`);
// Enable run tests button
document.getElementById('runAllTestsBtn').disabled = false;
}
// Updated clearResults function for the benchmark
function clearResults() {
// Reset results table
const resultsRows = document.getElementById('resultsBody').querySelectorAll('tr');
resultsRows.forEach(row => {
const cells = row.querySelectorAll('td');
cells[1].textContent = '-'; // Render
cells[2].textContent = '-'; // Update
cells[3].textContent = '-'; // Sort
cells[4].textContent = '-'; // Filter
cells[5].textContent = '-'; // Memory
cells[6].textContent = 'Pending'; // Status
});
// Reset results data
for (const framework in results) {
results[framework] = { render: [], update: [], sort: [], filter: [], memory: [] };
}
// Reset progress
updateProgress(0);
// Clean up other frameworks' containers
// const containers = document.querySelectorAll('.framework-container');
// containers.forEach(container => {
// container.style.display = 'none';
// // Keep original container but clear contents of children
// // This preserves the framework's container while removing dynamic content
// Array.from(container.children).forEach(child => {
// if (child.tagName === 'H2') return; // Keep the heading
// child.innerHTML = '';
// });
// });
// Reset chart
if (chart) {
chart.destroy();
chart = null;
}
logMessage('Results cleared');
// Reset test state
currentFrameworkIndex = 0;
currentIteration = 0;
}
function startTests() {
clearResults();
document.getElementById('runAllTestsBtn').disabled = true;
document.getElementById('generateDataBtn').disabled = true;
document.getElementById('clearResultsBtn').disabled = true;
logMessage(`Starting benchmark tests with ${iterationCount} iterations per framework...`);
const frameworks = ['LightBind', 'AngularJS', 'Vue.js', 'React'];
currentFrameworkIndex = 0;
currentIteration = 0;
runNextTest();
}
function runNextTest() {
const frameworks = ['LightBind', 'AngularJS', 'Vue.js', 'React'];
if (currentIteration >= iterationCount) {
currentIteration = 0;
currentFrameworkIndex++;
}
if (currentFrameworkIndex >= frameworks.length) {
// All tests completed
finalizeResults();
return;
}
const framework = frameworks[currentFrameworkIndex];
const iteration = currentIteration + 1;
const totalTests = frameworks.length * iterationCount;
const testsCompleted = (currentFrameworkIndex * iterationCount) + currentIteration;
const progressPercent = (testsCompleted / totalTests) * 100;
updateProgress(progressPercent);
logMessage(`Testing ${framework} (Iteration ${iteration}/${iterationCount})`);
// Run the appropriate test
switch (framework) {
case 'LightBind':
runLightBindTest();
break;
case 'AngularJS':
runAngularJSTest();
break;
case 'Vue.js':
runVueTest();
break;
case 'React':
runReactTest();
break;
}
currentIteration++;
}
async function runLightBindTest() {
try {
const container = document.getElementById('lightbind-container');
container.style.display = 'block';
function lightBindTableComponent(scope) {
scope.columns = [];
scope.rows = [];
scope.columns = [...testColumns];
scope.rows = [...testData];
scope.$render();
}
// Measure memory before
const memoryBefore = await getMemoryUsage();
// Initialize LightBind with test data
let component;
await measurePerformance('LightBind', 'render', async () => {
// Force a re-initialization
const element = container.querySelector('#lightBindTableComponent');
component = window.LightBind.initializeComponent(element, lightBindTableComponent);
});
// Measure update all
await measurePerformance('LightBind', 'update', async () => {
// Update all rows with modified data
const updatedData = testData.map(row => {
const newRow = { ...row };
for (let i = 0; i < testColumns.length; i++) {
if (typeof newRow[`field${i}`] === 'string') {
newRow[`field${i}`] = newRow[`field${i}`] + ' (updated)';
} else if (typeof newRow[`field${i}`] === 'number') {
newRow[`field${i}`] = newRow[`field${i}`] + 1;
}
}
return newRow;
});
component.scope.rows = updatedData;
component.scope.$render();
// await new Promise(resolve => setTimeout(resolve, 1000));
});
// Measure sort
await measurePerformance('LightBind', 'sort', async () => {
// Sort by first column
const sortedData = [...component.scope.rows].sort((a, b) => {
return a.field0.localeCompare(b.field0);
});
component.scope.rows = sortedData;
component.scope.$render();
});
// Measure filter
await measurePerformance('LightBind', 'filter', async () => {
// Filter to show only even-numbered rows
const filteredData = testData.filter(row => row.id % 2 === 0);
component.scope.rows = filteredData;
component.scope.$render();
});
// Measure memory after
const memoryAfter = await getMemoryUsage();
const memoryIncrease = memoryAfter - memoryBefore;
results['LightBind'].memory.push(memoryIncrease);
container.style.display = 'none';
updateResultsTable('LightBind');
// Move to next test
setTimeout(runNextTest, 500);
} catch (error) {
logMessage(`Error in LightBind test: ${error.message}`);
console.error('LightBind test error:', error);
// Mark as error in results
results['LightBind'].error = error.message;
updateResultsTable('LightBind', true);
// Continue with next test
setTimeout(runNextTest, 500);
}
}
async function runAngularJSTest() {
try {
const container = document.getElementById('angularjs-container');
container.style.display = 'block';
// Get the Angular scope
let scope = angular.element(container).scope();
// If no scope is found, bootstrap Angular on the container
if (!scope) {
angular.bootstrap(container, ['benchmarkApp']);
scope = angular.element(container).scope();
}
// Measure memory before
const memoryBefore = await getMemoryUsage();
// Measure render
await measurePerformance('AngularJS', 'render', async () => {
if (scope) {
scope.$apply(function () {
scope.columns = [...testColumns];
scope.rows = [...testData];
});
} else {
throw new Error("Could not get AngularJS scope");
}
});
// Measure update all
await measurePerformance('AngularJS', 'update', async () => {
if (scope) {
scope.$apply(function () {
// Update all rows with modified data
scope.rows = testData.map(row => {
const newRow = { ...row };
for (let i = 0; i < testColumns.length; i++) {
if (typeof newRow[`field${i}`] === 'string') {
newRow[`field${i}`] = newRow[`field${i}`] + ' (updated)';
} else if (typeof newRow[`field${i}`] === 'number') {
newRow[`field${i}`] = newRow[`field${i}`] + 1;
}
}
return newRow;
});
});
}
});
// Measure sort
await measurePerformance('AngularJS', 'sort', async () => {
if (scope) {
scope.$apply(function () {
// Sort by first column
scope.rows = [...scope.rows].sort((a, b) => {
return a.field0.localeCompare(b.field0);
});
});
}
});
// Measure filter
await measurePerformance('AngularJS', 'filter', async () => {
if (scope) {
scope.$apply(function () {
// Filter to show only even-numbered rows
scope.rows = testData.filter(row => row.id % 2 === 0);
});
}
});
// Measure memory after
const memoryAfter = await getMemoryUsage();
const memoryIncrease = memoryAfter - memoryBefore;
results['AngularJS'].memory.push(memoryIncrease);
container.style.display = 'none';
updateResultsTable('AngularJS');
// Move to next test
setTimeout(runNextTest, 500);
} catch (error) {
logMessage(`Error in AngularJS test: ${error.message}`);
console.error('AngularJS test error:', error);
// Mark as error in results
results['AngularJS'].error = error.message;
updateResultsTable('AngularJS', true);
// Continue with next test
setTimeout(runNextTest, 500);
}
}
async function runVueTest() {
try {
const container = document.getElementById('vue-container');
container.style.display = 'block';
// Measure memory before
const memoryBefore = await getMemoryUsage();
// Check if Vue app exists and clean up properly depending on Vue version
if (window.vueApp) {
try {
// Vue 3
if (typeof window.vueApp.unmount === 'function') {
window.vueApp.unmount();
}
// Vue 2
else if (typeof window.vueApp.$destroy === 'function') {
window.vueApp.$destroy();
}
} catch (e) {
console.warn("Error cleaning up Vue app:", e);
}
window.vueApp = null;
}
// Clear the Vue app container
const vueAppContainer = document.getElementById('vue-app');
if (vueAppContainer) {
vueAppContainer.innerHTML = `
<table class="data-table">
<thead>
<tr>
<th v-for="col in columns" :key="col.id">{{ col.name }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in rows" :key="row.id" :class="'row-' + (index % 2 === 0 ? 'even' : 'odd')">
<td v-for="(value, key) in row" :key="key">{{ value }}</td>
</tr>
</tbody>
</table>
`;
}
// Measure render
await measurePerformance('Vue.js', 'render', async () => {
// Check which Vue version is available
if (typeof Vue.createApp === 'function') {
// Vue 3
window.vueApp = Vue.createApp({
data() {
return {
columns: [...testColumns],
rows: [...testData]
};
}
}).mount('#vue-app');
} else if (typeof Vue === 'function') {
// Vue 2
window.vueApp = new Vue({
el: '#vue-app',
data: {
columns: [...testColumns],
rows: [...testData]
}
});
} else {
throw new Error("No compatible Vue version found");
}
});
// Measure update all
await measurePerformance('Vue.js', 'update', async () => {
if (window.vueApp) {
// Update all rows with modified data
window.vueApp.rows = testData.map(row => {
const newRow = { ...row };
for (let i = 0; i < testColumns.length; i++) {
if (typeof newRow[`field${i}`] === 'string') {
newRow[`field${i}`] = newRow[`field${i}`] + ' (updated)';
} else if (typeof newRow[`field${i}`] === 'number') {
newRow[`field${i}`] = newRow[`field${i}`] + 1;
}
}
return newRow;
});
}
});
// Measure sort
await measurePerformance('Vue.js', 'sort', async () => {
if (window.vueApp) {
// Sort by first column
window.vueApp.rows = [...window.vueApp.rows].sort((a, b) => {
return a.field0.localeCompare(b.field0);
});
}
});
// Measure filter
await measurePerformance('Vue.js', 'filter', async () => {
if (window.vueApp) {
// Filter to show only even-numbered rows
window.vueApp.rows = testData.filter(row => row.id % 2 === 0);
}
});
// Measure memory after
const memoryAfter = await getMemoryUsage();
const memoryIncrease = memoryAfter - memoryBefore;
results['Vue.js'].memory.push(memoryIncrease);
container.style.display = 'none';
updateResultsTable('Vue.js');
// Move to next test
setTimeout(runNextTest, 500);
} catch (error) {
logMessage(`Error in Vue.js test: ${error.message}`);
console.error('Vue.js test error:', error);
// Mark as error in results
results['Vue.js'].error = error.message;
updateResultsTable('Vue.js', true);
// Continue with next test
setTimeout(runNextTest, 500);
}
}
async function runReactTest() {
try {
const container = document.getElementById('react-container');