Prototype vs Non-Prototype

JavaScript performance comparison

Revision 4 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 Person(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    getFullName = function() {
       return this.firstName + " " + this.lastName;
    };
  }
 
  function Person2(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.getFullName = function() {
      return this.firstName + " " + this.lastName;
    };
  }
</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 person = new Person("Jeremy", "McPeak");
pending…
Non-Prototype (Nested)
var person2 = new Person2("Jeremy", "McPeak");
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