jit optimization

Benchmark created on


Preparation HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<canvas id="c"></canvas>
 
<script>
  var SIZE = 500;
  var canvas = document.getElementById('c');
  canvas.style.width = SIZE + "px";
  canvas.style.heigth = SIZE + "px";
  
  
  
  function Processor(canvas) {
     this.canvas = canvas;
     //this.color = [1,2,3];
     var ctx = canvas.getContext('2d');
     ctx.width = ctx.heigth = SIZE;
     this.ctx = ctx;
     this.image_data = ctx.getImageData(0, 0, SIZE, SIZE);
  }
  _.extend(Processor.prototype, {color : [1,2,3]});
  Processor.prototype.run = function() {
      var pixel_pos;
      var image_data = this.image_data;
      var color = this.color;
      for(var i=0; i < SIZE; ++i) {
         for(var j=0; j < SIZE; ++j) {
             pixel_pos = (j*SIZE + i) * 4;
             image_data[pixel_pos + 0] = color[0];
             image_data[pixel_pos + 1] = color[1];
             image_data[pixel_pos + 2] = color[2];
          }
      }       
      this.ctx.putImageData(image_data, 0, 0);     
  }
  
  Processor.prototype.run2 = function() {
      var pixel_pos;
      var image_data = this.image_data;
      var color = [1,2,3];
      for(var i=0; i < SIZE; ++i) {
         for(var j=0; j < SIZE; ++j) {
             pixel_pos = (j*SIZE + i) * 4;
             image_data[pixel_pos + 0] = color[0];
             image_data[pixel_pos + 1] = color[1];
             image_data[pixel_pos + 2] = color[2];
          }
      }       
     this.ctx.putImageData(image_data, 0, 0);      
  }
  
  var processor = new Processor(canvas);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
this reference
processor.run();
ready
constant reference
processor.run2();
ready

Revisions

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