Prototype Operator Performance

JavaScript performance comparison

Test case created by Fred Chien

Preparation code

<script>
  var i;
  var A, A_instance;
  var B, B_instance;
  var C, C_instance;

  A = function() {
    this.message = function(s) {
      var msg = s + '';
    };
    this.addition = function(i, j) {
      return (i * 2 + j * 2) / 2;
    };
  };
  A_instance = new A();

  B = function() {};
  B.prototype.message = function(s) {
    var msg = s + '';
  };
  B.prototype.addition = function(i, j) {
    return (i * 2 + j * 2) / 2;
  };
  B_instance = new B();

  C = function() {
    C.prototype.message = function(s) {
      var msg = s + '';
    };
    C.prototype.addition = function(i, j) {
      return (i * 2 + j * 2) / 2;
    };
  };
  C_instance = new C();
</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 method is declared into class
A_instance.message('Hi');
A_instance.addition(i, 2);
pending…
B method is declared outside class by using protoype keyword
B_instance.message('Hi');
B_instance.addition(i, 2);
pending…
C method is declared into class by using protoype keyword
C_instance.message('Hi');
C_instance.addition(i, 2);
pending…
Create A instance and run methods
A_instance = new A();
A_instance.message('Hi');
A_instance.addition(i, 2);
pending…
Create B instance and run methods
B_instance = new B();
B_instance.message('Hi');
B_instance.addition(i, 2);
pending…
Create C instance and run methods
C_instance = new C();
C_instance.message('Hi');
C_instance.addition(i, 2);
pending…

Compare results of other browsers

Revisions

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

0 Comments