const now = performance.now(); for (let i = 0; i < 10000; i++) { new vm.Script(code, { produceCachedData: true, cachedData: buffer }); } console.log(performance.now() - now);
const now = performance.now(); for (let i = 0; i < 10000; i++) { new vm.Script(code, { produceCachedData: true }); } console.log(performance.now() - now);
第一部分的耗时要比第二次少很多。
提供 buffer 并不能解决相同函数第一次执行时的长耗时
1 2 3 4 5 6 7 8
const render = ctx.module.exports.render;
render(); for (let i = 0; i < 100; i++) { const now = performance.now(); render(); console.log(performance.now() - now); }