Get - class vs object (v3)

Revision 3 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Class based
class MyClass {
  constructor(x) {
    this._x = x
  }
  get x() {
  			let z = '0';
  			for(let i = 0; i < 1000000; i++) {
  				z += i;
  			}
    		return z
  }
}

const classObj = new MyClass(10);
ready
Object based
function make(y) {
	return {
  		_x: y,
  		get x() {
  			let z = '0';
  			for(let i = 0; i < 1000000; i++) {
  				z += i;
  			}
    		return z
  		}
	};
}

const otherObj = Object.assign({}, make(10))
ready

Revisions

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