-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperformance-test.html
More file actions
239 lines (209 loc) · 9.11 KB
/
Copy pathperformance-test.html
File metadata and controls
239 lines (209 loc) · 9.11 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>countVisibleDots Performance Test</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.test-result {
margin: 10px 0;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
.fast { background-color: #d4edda; }
.medium { background-color: #fff3cd; }
.slow { background-color: #f8d7da; }
button {
padding: 10px 20px;
margin: 10px 5px;
font-size: 16px;
cursor: pointer;
}
#results {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>countVisibleDots Performance Test</h1>
<p>This test measures the performance of the countVisibleDots function with different data sizes and viewport scenarios.</p>
<button onclick="runAllTests()">Run All Tests</button>
<button onclick="clearResults()">Clear Results</button>
<div id="results"></div>
<script type="module">
// Import the countVisibleDots function
function countVisibleDots(data, transform, viewBox, defaultSize = 2) {
if (!data || !data.length || !transform || !viewBox) return 0;
const { k, x: tx, y: ty } = transform;
const [vbX, vbY, vbW, vbH] = viewBox;
// Calculate visible data bounds (inverse transform)
const visibleLeft = (vbX - tx) / k;
const visibleRight = (vbX + vbW - tx) / k;
const visibleTop = (vbY - ty) / k;
const visibleBottom = (vbY + vbH - ty) / k;
let visibleCount = 0;
for (const dot of data) {
const radius = (dot.size || defaultSize) / 2;
// Check if dot (including its radius) intersects with visible area
if (dot.x + radius >= visibleLeft &&
dot.x - radius <= visibleRight &&
dot.y + radius >= visibleTop &&
dot.y - radius <= visibleBottom) {
visibleCount++;
}
}
return visibleCount;
}
// Generate test data
function generateDots(count, bounds = { minX: 0, maxX: 1000, minY: 0, maxY: 1000 }) {
const dots = [];
for (let i = 0; i < count; i++) {
dots.push({
id: i,
x: Math.random() * (bounds.maxX - bounds.minX) + bounds.minX,
y: Math.random() * (bounds.maxY - bounds.minY) + bounds.minY,
size: Math.random() * 8 + 2 // Random size between 2-10
});
}
return dots;
}
// Test scenarios
const testScenarios = [
{
name: "Small Dataset - All Visible",
dotCount: 1000,
viewBox: [0, 0, 1000, 1000],
transform: { k: 1, x: 0, y: 0 },
bounds: { minX: 0, maxX: 1000, minY: 0, maxY: 1000 }
},
{
name: "Medium Dataset - All Visible",
dotCount: 10000,
viewBox: [0, 0, 1000, 1000],
transform: { k: 1, x: 0, y: 0 },
bounds: { minX: 0, maxX: 1000, minY: 0, maxY: 1000 }
},
{
name: "Large Dataset - All Visible",
dotCount: 100000,
viewBox: [0, 0, 1000, 1000],
transform: { k: 1, x: 0, y: 0 },
bounds: { minX: 0, maxX: 1000, minY: 0, maxY: 1000 }
},
{
name: "Large Dataset - Zoomed In (10% visible)",
dotCount: 100000,
viewBox: [0, 0, 100, 100],
transform: { k: 10, x: -4500, y: -4500 },
bounds: { minX: 0, maxX: 1000, minY: 0, maxY: 1000 }
},
{
name: "Large Dataset - Zoomed Out (All visible)",
dotCount: 100000,
viewBox: [0, 0, 2000, 2000],
transform: { k: 0.5, x: 500, y: 500 },
bounds: { minX: 0, maxX: 1000, minY: 0, maxY: 1000 }
},
{
name: "Extreme Dataset - Zoomed In",
dotCount: 500000,
viewBox: [0, 0, 50, 50],
transform: { k: 20, x: -9000, y: -9000 },
bounds: { minX: 0, maxX: 1000, minY: 0, maxY: 1000 }
}
];
function runTest(scenario, iterations = 5) {
const dots = generateDots(scenario.dotCount, scenario.bounds);
const times = [];
let visibleCount = 0;
// Warm-up run
countVisibleDots(dots, scenario.transform, scenario.viewBox);
// Actual test runs
for (let i = 0; i < iterations; i++) {
const startTime = performance.now();
visibleCount = countVisibleDots(dots, scenario.transform, scenario.viewBox);
const endTime = performance.now();
times.push(endTime - startTime);
}
const avgTime = times.reduce((sum, time) => sum + time, 0) / times.length;
const minTime = Math.min(...times);
const maxTime = Math.max(...times);
return {
scenario: scenario.name,
dotCount: scenario.dotCount,
visibleCount,
avgTime: avgTime.toFixed(3),
minTime: minTime.toFixed(3),
maxTime: maxTime.toFixed(3),
throughput: (scenario.dotCount / avgTime * 1000).toFixed(0) // dots per second
};
}
function formatResult(result) {
const timeClass = result.avgTime < 5 ? 'fast' : result.avgTime < 20 ? 'medium' : 'slow';
const visibilityPercent = ((result.visibleCount / result.dotCount) * 100).toFixed(1);
return `
<div class="test-result ${timeClass}">
<h3>${result.scenario}</h3>
<p><strong>Dataset Size:</strong> ${result.dotCount.toLocaleString()} dots</p>
<p><strong>Visible Dots:</strong> ${result.visibleCount.toLocaleString()} (${visibilityPercent}%)</p>
<p><strong>Performance:</strong></p>
<ul>
<li>Average Time: ${result.avgTime}ms</li>
<li>Min Time: ${result.minTime}ms</li>
<li>Max Time: ${result.maxTime}ms</li>
<li>Throughput: ${result.throughput.toLocaleString()} dots/sec</li>
</ul>
</div>
`;
}
window.runAllTests = function() {
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = '<h2>Running Tests...</h2>';
const allResults = [];
// Run tests sequentially to avoid interference
let currentTest = 0;
function runNextTest() {
if (currentTest >= testScenarios.length) {
// All tests complete, show summary
let html = '<h2>Test Results</h2>';
allResults.forEach(result => {
html += formatResult(result);
});
// Add summary
const totalDots = allResults.reduce((sum, r) => sum + r.dotCount, 0);
const avgThroughput = allResults.reduce((sum, r) => sum + parseInt(r.throughput), 0) / allResults.length;
html += `
<div class="test-result">
<h3>Summary</h3>
<p>Total dots processed: ${totalDots.toLocaleString()}</p>
<p>Average throughput: ${avgThroughput.toFixed(0).toLocaleString()} dots/sec</p>
<p>Function appears to be O(n) linear - performance scales predictably with data size.</p>
</div>
`;
resultsDiv.innerHTML = html;
return;
}
resultsDiv.innerHTML = `<h2>Running Test ${currentTest + 1}/${testScenarios.length}: ${testScenarios[currentTest].name}</h2>`;
// Use setTimeout to prevent UI blocking
setTimeout(() => {
const result = runTest(testScenarios[currentTest]);
allResults.push(result);
currentTest++;
runNextTest();
}, 100);
}
runNextTest();
};
window.clearResults = function() {
document.getElementById('results').innerHTML = '';
};
</script>
</body>
</html>