try and catch performance

JavaScript performance comparison

Test case created by asdfsdafsa

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var collisionCount = 0;
  var couple = [];
  for(var i = 0 ; i < 100; i++){
  	couple.push({x:Math.random(),y:Math.random()});
  }
  
  //Note: try and catch of a() and c() have the exact same code.
  
  a = function(){
  	try {
           for(var i = 0 ; i < couple.length; i++){
               for(var j = 0 ; j < couple.length; j++){
                  var vx = couple[i].x-couple[j].x;
                  var vy = couple[i].y-couple[j].y;
                  if(vx*vx + vy*vy < 0.1)
                     collisionCount++;
               }
           }
  	} catch(err){
  	
  	}
  }
  b = function(){
  	try {
          c();
  	} catch(err){
  	
  	}
  }
  c = function(){
       for(var i = 0 ; i < couple.length; i++){
           for(var j = 0 ; j < couple.length; j++){
              var vx = couple[i].x-couple[j].x;
              var vy = couple[i].y-couple[j].y;
              if(vx*vx + vy*vy < 0.1)
                 collisionCount++;
           }
       }
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
a
a();
pending…
b
b();
pending…

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

Compare results of other browsers

0 Comments