Skip to content

Instantly share code, notes, and snippets.

@1wheel
Last active August 22, 2016 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1wheel/5e4c58d0b2a5386bad2d to your computer and use it in GitHub Desktop.
Save 1wheel/5e4c58d0b2a5386bad2d to your computer and use it in GitHub Desktop.
fps-meter
<!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