Prototype vs Non-Prototype

JavaScript performance comparison

Revision 5 of this test case created

Info

Testing the difference in execution time of creating objects using the prototype and not using it.

Preparation code

<script>
  function PersonLame(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
  }
 
  PersonLame.prototype.getFullName = function() {
    return this.firstName + " " + this.lastName;
  };
 
  function PersonAwesome(firstName, lastName) {
    var firstName   = firstName
      , lastName    = lastName
      , fullName = function() { return firstName + " " + lastName; }
      ;
    return { fullName: fullName };
  }
</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 lamer = new PersonLame("Jeremy", "McPeak");
pending…
Nested
var awesome = new PersonAwesome("Jeremy", "McPeak");
pending…
Prototype (Full Name)
var lamer = new PersonLame("Jeremy", "McPeak").getFullName();
 
pending…
Nested (Full Name)
var awesome = new PersonAwesome("Jeremy", "McPeak").fullName();
 
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