drawImage whole pixels
JavaScript performance comparison
Preparation code
<canvas id="screen" width="1024" height="768">
</canvas>
<script>
var context = document.getElementById("screen").getContext("2d");
var cellBackgroundLeft = document.createElement("img");
cellBackgroundLeft.src = "http://img201.imageshack.us/img201/2698/cellbackgroundleft.png";
var cellBackgroundRight = document.createElement("img");
cellBackgroundRight.src = "http://img194.imageshack.us/img194/156/cellbackgroundright.png";
var cellBackgroundMiddle = document.createElement("img");
cellBackgroundMiddle.src = "http://img824.imageshack.us/img824/2954/cellbackgroundmiddle.png";
function drawCellMiddleRect(x, y, width) {
context.fillStyle = "#4b4f57";
context.drawImage(cellBackgroundLeft, x, y);
context.fillRect(x + 4, y, width - 2 * 4, 63);
context.drawImage(cellBackgroundRight, x + width - 4, y);
}
function drawCellMiddleImage(x, y, width) {
context.fillStyle = "#4b4f57";
context.drawImage(cellBackgroundLeft, x, y);
context.drawImage(cellBackgroundMiddle, x + 4, y, width - 2 * 4, 63);
context.drawImage(cellBackgroundRight, x + width - 4, y);
}
function roundRect(ctx, x, y, width, height, radius, fill, stroke) {
if (!stroke) {
stroke = true;
}
if (!radius) {
radius = 5;
}
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
if (fill) {
ctx.fill();
}
}
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
drawCellMiddleRect |
|
pending… |
drawCellMiddleImage |
|
pending… |
roundRect |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published by skyblue
- Revision 12: published
- Revision 13: published
- Revision 14: published by ryan jacobson
- Revision 16: published
- Revision 17: published
0 comments