Skip to content

Instantly share code, notes, and snippets.

@ide
Created August 13, 2017 07:06
Show Gist options
  • Save ide/39c5d7f6306bd7d0cab8c4eab1acaad5 to your computer and use it in GitHub Desktop.
Save ide/39c5d7f6306bd7d0cab8c4eab1acaad5 to your computer and use it in GitHub Desktop.
Node VM context creation benchmark
const vm = require('vm');
const batchSize = 100;
const limit = batchSize * 30;
let contexts = new Array(limit);
for (let i = 0; i < limit / batchSize; i++) {
// Compute the average time for each batch
let start = Date.now();
for (let j = 0; j < batchSize; j++) {
contexts.push(vm.createContext({}));
}
let averageTime = (Date.now() - start) / batchSize;
console.log(
`Average time to create contexts [${i * batchSize}...${(i + 1) * batchSize -
1}] = ${averageTime}ms`
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment