Last active
March 29, 2016 17:14
-
-
Save mems/39831f33d2a3372af1ff to your computer and use it in GitHub Desktop.
Canvas stress test. Usefull for detect low-end devices or old tablets/smartphones
This file contains hidden or 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 PUBLIC> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<script> | |
// Polyfill | |
window.performance = (window.performance || { | |
offset: Date.now(), | |
now: function now(){ | |
return Date.now() - this.offset; | |
} | |
}); | |
var canvas = document.createElement("CANVAS"); | |
canvas.width = canvas.height = 1000; | |
var context = canvas.getContext("2d"); | |
var t0 = performance.now(); | |
// first call drawImage twice. Required by Chrome, Opera, IE and Safari Mobile: it take time at cold start, not in next reloads | |
context.drawImage(canvas, 0, 0, 1, 1); | |
context.drawImage(canvas, 0, 0, 1, 1); | |
var t1 = performance.now(); | |
for(var iter = 0; iter < 50; iter++){ | |
context.translate(-10, -10); | |
context.rotate(Math.PI/2); | |
context.translate(10, 10); | |
context.drawImage(canvas, 0, 0, 20, 20, 0, 0, 19, 19); | |
} | |
var t2 = performance.now(); | |
document.body.textContent = "\ncanvas stress test: "+(t2 - t1).toFixed(4)+"ms (init: "+(t1 - t0).toFixed(4)+"ms)"; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also https://w3c.github.io/frame-timing/