4 <title>Timing test for blur filter</title>
15 var NUM_ITERATIONS = 10;
17 var currentIteration = 0;
18 var currentRadius = 0;
19 var testIsRunning = false;
24 document.querySelector("button").addEventListener("click", run, false);
25 image = document.querySelector("img");
27 // Fill the image with generated content. We can't use a canvas directly,
28 // since that gets composited.
29 var canvas = document.createElement("canvas");
30 canvas.width = WIDTH * window.devicePixelRatio;
31 canvas.height = HEIGHT * window.devicePixelRatio;
33 // Fill the canvas with some generated content.
34 var ctx = canvas.getContext("2d");
35 ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
37 for (var i = 0; i < WIDTH; i += 20) {
38 for (var j = 0; j < HEIGHT; j += 20) {
39 ctx.fillStyle = "rgb(" + Math.round(i / WIDTH * 255) + ", " + Math.round(j / HEIGHT * 255) + ", " + (i % 40 ? 64 : 192) + ")";
40 ctx.fillRect(i, j, 20, 20);
44 image.src = canvas.toDataURL();
54 startTime = Date.now();
60 var usedRadius = (currentIteration % 2) ? (MAX_RADIUS - currentRadius) : currentRadius;
61 image.style.webkitFilter = "blur(" + usedRadius + "px)";
63 if (currentRadius > MAX_RADIUS) {
68 if (currentIteration < NUM_ITERATIONS)
75 testIsRunning = false;
76 var elapsedTime = (Date.now() - startTime) / 1000;
77 var result = document.createElement("p");
78 result.textContent = (NUM_ITERATIONS * MAX_RADIUS) + " blurs done in " + elapsedTime + " seconds";
79 document.body.appendChild(result);
80 if (window.testRunner)
81 testRunner.notifyDone();
84 window.addEventListener("load", init, false);
90 <button>Start</button>