drawImage whole pixels (v12)

Revision 12 of this benchmark created on


Preparation HTML

<canvas id="screen"></canvas>
<script>
  var ctx = document.getElementById("screen").getContext("2d");
  var image = document.createElement("img");
  image.src = "http://icons.iconarchive.com/icons/ph03nyx/super-mario/48/Retro-Mushroom-1UP-2-icon.png";

        function roundNumber(number)
                {
                return (~~ (number + (number > 0 ?.5 : -.5)));
                }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
whole pixel
ctx.drawImage(image, 0, 0);
ready
sub pixel
ctx.drawImage(image, 0.5, 0.5);
ready
whole pixel2
ctx.drawImage(image, 1.1|0, 1.1|0);
ready
whole pixel3
ctx.drawImage(image, 1.6>>0, 1.6>>0);
ready
whole pixel4
ctx.drawImage(image, parseInt(1.6), parseInt(1.6));
ready
whole pixel5
ctx.drawImage(image, roundNumber(1.6), roundNumber(1.6));
ready
whole pixel6
var x = (~~ (1.5+ (1.5> 0 ?.5 : -.5)));
var y = (~~ (1.5+ (1.5> 0 ?.5 : -.5)));
ctx.drawImage(image, x, y);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.