Created
August 13, 2017 07:06
-
-
Save ide/39c5d7f6306bd7d0cab8c4eab1acaad5 to your computer and use it in GitHub Desktop.
Node VM context creation benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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