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
|
<!DOCTYPE html>
<html>
<!--
Copyright 2011 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>FPS Display</title>
<script type="text/javascript" src="../base.js"></script>
<script type="text/javascript">
goog.require('goog.debug.FpsDisplay');
goog.require('goog.string');
</script>
<body>
<div id="fpsdisplay"></div>
<button onclick="doSomethingExpensive()">Do something expensive and watch FPS decrease</button>
<button onclick="stop()">Stop expensive action</button>
<button onclick="display()">Alert FPS</button>
<div id="output"></div>
</body>
<script>
var fpsDisplay = new goog.debug.FpsDisplay();
fpsDisplay.render(document.getElementById('fpsdisplay'));
var handle;
function doSomethingExpensive() {
var output = document.getElementById('output');
var appender = function() {
output.innerHTML += goog.string.repeat('<div>a </div>', 20);
// Force layout.
var b = output.offsetHeight;
}
handle = window.setInterval(appender, 20);
}
function stop() {
window.clearInterval(handle);
}
function display() {
alert(fpsDisplay.getFps());
}
</script>
</html>
|