Try Catch

JavaScript performance comparison

Test case created by Lorin Klugman

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var person = function(first_name,last_name) {
      this.init = function(first_name,last_name) {
          if (first_name) {
              this.first_name = first_name;
          };
          if (last_name) {
              this.last_name = last_name;
          };
      };
      this.getFirstName = function() {
          return this.first_name;
      };
      this.setFirstName=function(first_name) {
          this.first_name = first_name;
      };
      this.getLastName = function() {
          return this.last_name;
      };
      this.setLastName= function(last_name) {
          this.last_name = last_name;
      };
      this.init(first_name,last_name);
  };
  var joe = new person("joe","smo");
  

};
</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
No try/catch
var firstName = null;
firstName = joe.getFirstName();
console.log(firstName);
pending…
With try/catch
var lastName = null;
try {
    lastName = joe.getLastName();
    console.log(lastName);
} catch(error) {
    console.log("An error occurred");
}
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