Last active
August 22, 2016 02:21
-
-
Save 1wheel/5e4c58d0b2a5386bad2d to your computer and use it in GitHub Desktop.
fps-meter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
</style> | |
<body></body> | |
<script src="/1wheel/raw/67b47524ed8ed829d021/d3-3.5.5.js"></script> | |
<script src="/1wheel/raw/67b47524ed8ed829d021/lodash-3.8.0.js"></script> | |
<script src='/1wheel/raw/1b6758978dc2d52d3a37/d3-jetpack.js'></script> | |
<script src='/1wheel/raw/1b6758978dc2d52d3a37/d3-starterkit.js'></script> | |
<script> | |
fpsInit() | |
function fpsInit(){ | |
var counter = d3.select('body').append('div') | |
.style({ | |
'font-family': 'monospace', | |
position: 'fixed', | |
'padding': '8px', | |
'background': 'black', | |
'color': 'white' | |
}) | |
var ticks = [] | |
d3.timer(function(t){ | |
ticks.push(t) | |
if (ticks.length > 15) ticks.shift() | |
var avgFrameLength = (_.last(ticks) - ticks[0])/ticks.length | |
counter.text(Math.round(1/avgFrameLength*1000) + ' fps') | |
//todo - line chart | |
}) | |
} | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment