-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-wasm.html
More file actions
240 lines (206 loc) Β· 9.41 KB
/
Copy pathtest-wasm.html
File metadata and controls
240 lines (206 loc) Β· 9.41 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WASM Integration Test</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #f5f5f5;
}
.test-section {
background: white;
padding: 20px;
margin: 10px 0;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.status {
padding: 10px;
margin: 10px 0;
border-radius: 4px;
font-weight: bold;
}
.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }
.info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
button {
background: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover { background: #0056b3; }
#console-output {
background: #f8f9fa;
border: 1px solid #dee2e6;
padding: 15px;
border-radius: 4px;
font-family: monospace;
white-space: pre-wrap;
max-height: 300px;
overflow-y: auto;
}
</style>
</head>
<body>
<h1>π§ͺ WASM Integration Test</h1>
<div class="test-section">
<h2>1. WebAssembly Support Check</h2>
<div id="wasm-support" class="status info">Checking...</div>
</div>
<div class="test-section">
<h2>2. WASM Module Loading Test</h2>
<div id="wasm-loading" class="status info">Testing...</div>
<button onclick="testWASMLoading()">Test WASM Loading</button>
</div>
<div class="test-section">
<h2>3. WASM Classes Test</h2>
<div id="wasm-classes" class="status info">Testing...</div>
<button onclick="testWASMClasses()">Test WASM Classes</button>
</div>
<div class="test-section">
<h2>4. Performance Test</h2>
<div id="performance-test" class="status info">Ready to test</div>
<button onclick="testPerformance()">Run Performance Test</button>
</div>
<div class="test-section">
<h2>5. Console Output</h2>
<div id="console-output"></div>
<button onclick="clearConsole()">Clear Console</button>
</div>
<script>
let consoleOutput = document.getElementById('console-output');
let wasmModule = null;
function log(message, type = 'info') {
const timestamp = new Date().toLocaleTimeString();
const logMessage = `[${timestamp}] ${message}\n`;
consoleOutput.textContent += logMessage;
console.log(message);
}
function clearConsole() {
consoleOutput.textContent = '';
}
// Test 1: WebAssembly Support
function checkWASMSupport() {
const wasmSupported = typeof WebAssembly !== 'undefined';
const supportElement = document.getElementById('wasm-support');
if (wasmSupported) {
supportElement.textContent = 'β
WebAssembly is supported in this browser';
supportElement.className = 'status success';
log('β
WebAssembly is supported');
} else {
supportElement.textContent = 'β WebAssembly is not supported in this browser';
supportElement.className = 'status error';
log('β WebAssembly is not supported');
}
}
// Test 2: WASM Module Loading
async function testWASMLoading() {
const loadingElement = document.getElementById('wasm-loading');
loadingElement.textContent = 'Loading WASM module...';
loadingElement.className = 'status info';
try {
log('π Attempting to load WASM module...');
// Try loading from the src directory
const module = await import('/src/shared/wasm/portfolio_engine.js');
log('β
WASM module imported successfully');
// Initialize the module
await module.default();
log('β
WASM module initialized successfully');
wasmModule = module;
loadingElement.textContent = 'β
WASM module loaded and initialized successfully';
loadingElement.className = 'status success';
} catch (error) {
log(`β WASM loading failed: ${error.message}`);
loadingElement.textContent = `β WASM loading failed: ${error.message}`;
loadingElement.className = 'status error';
}
}
// Test 3: WASM Classes
async function testWASMClasses() {
const classesElement = document.getElementById('wasm-classes');
if (!wasmModule) {
classesElement.textContent = 'β WASM module not loaded. Please run the loading test first.';
classesElement.className = 'status error';
return;
}
try {
log('π§ͺ Testing WASM classes...');
// Test FingerprintEngine
const fingerprintEngine = new wasmModule.FingerprintEngine();
const canvasFingerprint = fingerprintEngine.generate_canvas_fingerprint();
log(`β
FingerprintEngine: Canvas fingerprint generated (${canvasFingerprint.length} chars)`);
fingerprintEngine.free();
// Test AnalyticsEngine
const analyticsEngine = new wasmModule.AnalyticsEngine();
analyticsEngine.track_event('test', 'WASM integration test');
const engagementScore = analyticsEngine.get_engagement_score();
log(`β
AnalyticsEngine: Engagement score = ${engagementScore}`);
analyticsEngine.free();
// Test PerformanceMonitor
const performanceMonitor = new wasmModule.PerformanceMonitor();
performanceMonitor.update(performance.now());
const fps = performanceMonitor.get_average_fps();
log(`β
PerformanceMonitor: Average FPS = ${fps}`);
performanceMonitor.free();
classesElement.textContent = 'β
All WASM classes tested successfully';
classesElement.className = 'status success';
} catch (error) {
log(`β WASM classes test failed: ${error.message}`);
classesElement.textContent = `β WASM classes test failed: ${error.message}`;
classesElement.className = 'status error';
}
}
// Test 4: Performance Test
async function testPerformance() {
const perfElement = document.getElementById('performance-test');
perfElement.textContent = 'Running performance test...';
perfElement.className = 'status info';
if (!wasmModule) {
perfElement.textContent = 'β WASM module not loaded. Please run the loading test first.';
perfElement.className = 'status error';
return;
}
try {
log('β‘ Running performance comparison...');
// Test JS fingerprinting
const jsStart = performance.now();
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = 200;
canvas.height = 50;
ctx.fillText('JS Test', 10, 30);
const jsFingerprint = canvas.toDataURL();
const jsTime = performance.now() - jsStart;
// Test WASM fingerprinting
const wasmStart = performance.now();
const fingerprintEngine = new wasmModule.FingerprintEngine();
const wasmFingerprint = fingerprintEngine.generate_canvas_fingerprint();
const wasmTime = performance.now() - wasmStart;
fingerprintEngine.free();
const speedup = (jsTime / wasmTime).toFixed(2);
log(`π JS Fingerprinting: ${jsTime.toFixed(2)}ms`);
log(`π WASM Fingerprinting: ${wasmTime.toFixed(2)}ms`);
log(`π WASM Speedup: ${speedup}x faster`);
perfElement.textContent = `β
Performance test complete. WASM is ${speedup}x faster than JS`;
perfElement.className = 'status success';
} catch (error) {
log(`β Performance test failed: ${error.message}`);
perfElement.textContent = `β Performance test failed: ${error.message}`;
perfElement.className = 'status error';
}
}
// Initialize tests
checkWASMSupport();
</script>
</body>
</html>