Call with and without prototype

JavaScript performance comparison

Test case created by Cezary Tomczyk

Preparation code

<script>
  var O = function() {
      this.a = function() {
        var f1 = 5,
            f2 = 10;
        return f1 + f2;
      }
      this.b = function() {
        var f1 = 5,
            f2 = 10;
        return f1 * f2;
      }
      };

  var P = function() {};
  P.prototype.a = function() {
    var f1 = 5,
        f2 = 10;
    return f1 + f2;
  }
  P.prototype.b = function() {
    var f1 = 5,
        f2 = 10;
    return f1 * f2;
  }
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Prototype
var c = new P,
    a = c.a(),
    b = c.b();

var a = new P,
    s = c.a(),
    d = c.b();
pending…
Without prototype
var c = new O,
    a = c.a(),
    b = c.b();

var a = new O,
    s = c.a(),
    d = c.b();
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. Here’s a list of current revisions for this page:

0 comments

Add a comment