Files
a2f-service/examples/3d/performance-test.html
2025-12-29 11:22:51 +08:00

57 lines
1.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<title>性能测试</title>
<style>
body { font-family: monospace; padding: 20px; }
.log { margin: 5px 0; }
.warn { color: orange; }
.error { color: red; }
</style>
</head>
<body>
<h3>动画性能监控</h3>
<div id="logs"></div>
<script>
const logs = document.getElementById('logs');
// 监控 requestAnimationFrame 性能
let lastTime = performance.now();
let frameCount = 0;
let maxFrameTime = 0;
function monitorFrame() {
const now = performance.now();
const delta = now - lastTime;
if (frameCount > 0 && delta > 20) {
const log = document.createElement('div');
log.className = delta > 50 ? 'log error' : 'log warn';
log.textContent = `${frameCount}: ${delta.toFixed(2)}ms (目标: 16.67ms)`;
logs.appendChild(log);
if (delta > maxFrameTime) {
maxFrameTime = delta;
}
}
lastTime = now;
frameCount++;
if (frameCount < 300) {
requestAnimationFrame(monitorFrame);
} else {
const summary = document.createElement('div');
summary.className = 'log';
summary.textContent = `\n总结: 最大帧时间 ${maxFrameTime.toFixed(2)}ms`;
logs.appendChild(summary);
}
}
console.log('性能监控已启动将监控前300帧');
requestAnimationFrame(monitorFrame);
</script>
</body>
</html>