new with prototype vs return object

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function Foobar() {}
  
  Foobar.prototype.foo = function() { return "foo" }
  Foobar.prototype.bar = function() { return "bar" }
  Foobar.prototype.baz = function() { return "baz" }
  
  function Bazbar() {
      return {
          foo: function() { return "foo" },
          bar: function() { return "bar" },
          baz: function() { return "baz" }
      }
  }
  
  function Barfoo() {
      this.foo = function() { return "foo" };
      this.bar = function() { return "bar" };
      this.baz = function() { return "baz" };
  }
  

};

Benchmark.prototype.teardown = function() {
  delete window.Foobar
  delete window.Bazbar
  delete window.Barfoo

};
</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
with prototype
new Foobar();
pending…
with object return
new Bazbar();
pending…
with this-assignment
new Barfoo();
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