Created
September 7, 2014 11:10
-
-
Save zz85/961b710f806cbcb3d058 to your computer and use it in GitHub Desktop.
benchmark 2d canas strokes
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
var c = document.createElement('canvas'); | |
c.width = innerWidth; | |
c.height = innerHeight; | |
var ctx = c.getContext('2d'); | |
document.body.appendChild(c); | |
var last = performance.now(); | |
var delay = 0; | |
function animate() { | |
requestAnimationFrame(animate); | |
var now = performance.now(); | |
delay = (now - last) * 0.05 + delay * 0.95; | |
last = now; | |
ctx.clearRect(0, 0, c.width, c.height); | |
ctx.fillText(~~delay +'ms / ' + (1000/ delay | 0) + 'fps', 50, 50); | |
LINES = 2000; | |
ctx.lineWidth = LINE_WIDTH; | |
for (i=0; i < LINES; i++) { | |
// If test lines | |
ctx.beginPath(); | |
ctx.moveTo(50 + Math.random() * innerWidth * 0.8, 50 + Math.random() * innerHeight * 0.8); | |
ctx.lineTo(50 + Math.random() * innerWidth * 0.8, 50 + Math.random() * innerHeight * 0.8); | |
ctx.stroke(); | |
// If test curves | |
ctx.beginPath(); | |
ctx.moveTo(50 + Math.random() * innerWidth * 0.8, 50 + Math.random() * innerHeight * 0.8); | |
ctx.quadraticCurveTo( | |
50 + Math.random() * innerWidth * 0.8, 50 + Math.random() * innerHeight * 0.8, | |
50 + Math.random() * innerWidth * 0.8, 50 + Math.random() * innerHeight * 0.8); | |
ctx.stroke(); | |
} | |
} | |
animate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment