drawImage whole pixels (v9)

Revision 9 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 fasterRound(value)
  {
    return(~~(value+(value > 0 ? .5 : -.5)));
  }
  
  function fasterRoundPos(value)
  {
    return(~~(value+0.5));
  }
  function nop(value) { return(value); }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
whole pixel
ctx.drawImage(image, Math.round(0.5), Math.round(0.5));
ready
sub pixel
ctx.drawImage(image, 0.5, 0.5);
ready
whole pixels 2
ctx.drawImage(image, fasterRound(0.5), fasterRound(0.5));
ready
integer pixel
ctx.drawImage(image, 0, 0);
ready
whole pixels 3
ctx.drawImage(image, fasterRoundPos(0.5), fasterRoundPos(0.5));
ready
integer nop pixel
ctx.drawImage(image, nop(0), nop(0));
ready
whole pixels 4
ctx.drawImage(image, ~~(0.5+0.5), ~~(0.5+0.5));
ready
sub nop pixel
ctx.drawImage(image, nop(0.5), nop(0.5));
ready

Revisions

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