Fps Monitor
Runnable deck.gl example: Fps Monitor. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.
single HTML file · CDN dependencies onlyinterface may contain Chinese labels
Source
<!--
示例:渲染帧率
要点:六万个点每六帧更新一次半径,复用数据数组,右上角显示帧率
依赖:deck.gl 9.0 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>渲染帧率</title>
<style>
html,body{height:100%;margin:0;background:#0d1117}
body{display:flex;flex-direction:column;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#e6e8ec}
.bar{position:relative;z-index:5;flex:0 0 auto;padding:8px 12px;background:#161b22;border-bottom:1px solid #252c36;
display:flex;gap:14px;align-items:center;font-size:12px;color:#8b93a1;flex-wrap:wrap}
.bar b{color:#58a6ff;font-weight:600}
.bar label{display:flex;align-items:center;gap:5px;cursor:pointer}
.bar input[type=checkbox]{accent-color:#4f9ef8}
.bar input[type=range]{width:150px;accent-color:#4f9ef8}
.bar button{font:inherit;font-size:12px;padding:3px 10px;border-radius:4px;cursor:pointer;
border:1px solid #2f3947;background:#1d242e;color:#c9d3e0}
.bar button:hover{background:#26303d}
#cv{flex:1 1 auto;min-height:0;width:100%;display:block}
.fps{position:absolute;right:12px;top:52px;padding:6px 12px;background:rgba(16,22,32,0.88);
border:1px solid #2c3644;border-radius:6px;font:12px ui-monospace,Consolas,monospace;color:#7fc4ff}
.wrap{position:relative;flex:1 1 auto;min-height:0}
.wrap #cv{width:100%;height:100%}
</style>
</head>
<body>
<div class="bar"><span>点数 <b id="n">—</b></span><span>半径每六帧更新一次</span></div>
<div class="wrap">
<canvas id="cv"></canvas>
<div class="fps" id="fps">— fps</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/deck.gl@9.0.35/dist.min.js"></script>
<script>
(function () {
'use strict';
if (typeof deck === 'undefined') {
document.body.innerHTML =
'<div style="padding:24px;color:#ff8c74">deck.gl 加载失败,请检查能否访问 cdn.jsdelivr.net</div>';
return;
}
var N = 60000;
var data = [];
for (var i = 0; i < N; i++) {
data.push({
lng: 104 + Math.random() * 36,
lat: 22 + Math.random() * 24,
v: Math.random()
});
}
document.getElementById('n').textContent = N.toLocaleString();
var phase = 0;
function makeLayer() {
return new deck.ScatterplotLayer({
id: 'points',
data: data,
getPosition: function (d) { return [d.lng, d.lat]; },
getRadius: 1.6 + phase * 0.6,
radiusUnits: 'pixels',
radiusMinPixels: 1,
getFillColor: function (d) {
var t = d.v;
return [Math.round(80 + 150 * t), Math.round(180 - 70 * t), Math.round(255 - 120 * t), 165];
},
updateTriggers: { getRadius: phase },
useDevicePixels: false
});
}
var deckgl = new deck.Deck({
canvas: 'cv',
width: '100%',
height: '100%',
initialViewState: { longitude: 108, latitude: 34, zoom: 3.4, pitch: 30, bearing: 0 },
controller: true,
layers: [makeLayer()]
});
var frames = 0;
var mark = performance.now();
var tick = 0;
function loop(now) {
frames++;
tick++;
if (tick % 6 === 0) {
phase = 0.5 + 0.5 * Math.sin(now / 900);
deckgl.setProps({ layers: [makeLayer()] });
}
if (now - mark >= 1000) {
document.getElementById('fps').textContent = Math.round(frames * 1000 / (now - mark)) + ' fps';
frames = 0;
mark = now;
}
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
window.__deck = deckgl;
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.