Skip to content

Instantly share code, notes, and snippets.

@cevek
Last active October 19, 2018 20:21
Show Gist options
  • Save cevek/ec4f37e8c274b9587b224590decace69 to your computer and use it in GitHub Desktop.
Save cevek/ec4f37e8c274b9587b224590decace69 to your computer and use it in GitHub Desktop.
var foo, bar;
class Aaa {
constructor(a, b) {
this.a = a;
this.b = b;
}
}
class Bbb {
constructor(fn) {
fn(this);
}
static make(init) {
const obj = new this();
if (init) init(obj);
return obj;
}
}
class Ccc {
static make(init) {
const obj = new this();
if (init) init(obj);
return obj;
}
}
function abc() {
for (let j = 0; j < 1e7; j++) {
var x = new Aaa(() => foo, () => bar);
}
return x;
}
function abc2() {
for (let j = 0; j < 1e7; j++) {
var x = new Bbb(obj => {
(obj.a = () => foo), (obj.b = () => bar);
});
}
return x;
}
function abc3() {
for (let j = 0; j < 1e7; j++) {
var x = Ccc.make(obj => {
(obj.a = () => foo), (obj.b = () => bar);
});
}
return x;
}
var x = new Bbb(obj => {});
var x = new Bbb(obj => {});
var x = new Bbb(obj => {});
var x = new Bbb(obj => {});
var x = Ccc.make(obj => {});
var x = Ccc.make(obj => {});
var x = Ccc.make(obj => {});
var x = Ccc.make(obj => {});
console.time('perf');
abc();
console.timeEnd('perf');
console.time('perf');
abc2();
console.timeEnd('perf');
console.time('perf');
abc3();
console.timeEnd('perf');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment