Returning instances vs objects.

Benchmark created on


Description

Testing return of instances versus objects.

Setup

function Size(width, height) {
       this.width = width;
       this.height = height;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Returning new instances
(function() {
  var x = 10 / 2;
  var y = 5;
  return new Size(10, 5);
})();
ready
Returning new objects
(function() {
  var x = 10 / 2;
  var y = 5;
  return {
     width: x,
     height: y
  }
})();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.