Prototype vs Non-Prototype

JavaScript performance comparison

Test case created by Jeremy McPeak (Nettuts)


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

Preparation code

  function Person(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
  Person.prototype.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;

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
var person = new Person("Jeremy", "McPeak");
Non-Prototype (Nested)
var person2 = new Person2("Jeremy", "McPeak");

Compare results of other browsers


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:

1 comment

fgedgdf commented :


Add a comment