Get - class vs object

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Class based
class MyClass {
  constructor(x) {
    this._x = x.val;
  }
  get x() {
    return this._x;
  }
}

const classObj = new MyClass({val: 10});
classObj.x
ready
Object based
function make(y) {
	return {
  		...y,
  		get x() {
    		return y._x;
  		}
	};
}

const otherObj = make({_x: 10})
otherObj.x
ready

Revisions

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