prosperon/tests/bind_v_fn.js

25 lines
462 B
JavaScript
Raw Normal View History

2024-01-03 14:26:42 -06:00
var binds = [];
var a = {
n: 1,
test() { this.n++; }
};
var count = 10000000;
var start = Date.now();
for (var i = 0; i < count; i++)
binds.push(a.test.bind(a));
console.log(`Make bind time: ${Date.now()-start} ms`);
start = Date.now();
for (var i = 0; i < count; i++)
binds[i]();
console.log(`Bind time: ${Date.now()-start} ms`);
start = Date.now();
for (var i = 0; i < count; i++)
a['test']();
console.log(`Call time: ${Date.now()-start} ms`);