Test name | Executions per second |
---|---|
bind | 3340.2 Ops/sec |
closure | 263489.5 Ops/sec |
function fn1() {
return 1 + 1;
}
function fn2() {
return 2 + 2;
}
function fn3() {
return 3 + 3;
}
function fn4() {
return 4 + 4;
}
function createSomething() {
return [fn1.bind(null), fn2.bind(null), fn3.bind(null), fn4.bind(null)]
}
for (let i = 0; i < 100; i++) {
let [a, b, c, d] = createSomething();
for (let j = 0; j < 100; j++) {
a();
b();
c();
d();
}
}
function createSomething() {
function fn1() {
return 1 + 1;
}
function fn2() {
return 2 + 2;
}
function fn3() {
return 3 + 3;
}
function fn4() {
return 4 + 4;
}
return [fn1, fn2, fn3, fn4]
}
for (let i = 0; i < 100; i++) {
let [a, b, c, d] = createSomething();
for (let j = 0; j < 100; j++) {
a();
b();
c();
d();
}
}