Skip to content

Instantly share code, notes, and snippets.

@mooyoul
Created December 25, 2016 19:27
Show Gist options
  • Save mooyoul/dcbc852df8f3b0ceccdbef0330b58970 to your computer and use it in GitHub Desktop.
Save mooyoul/dcbc852df8f3b0ceccdbef0330b58970 to your computer and use it in GitHub Desktop.
VM `timeout` issue example
'use strict';
const
vm = require('vm'),
sandbox = {
current: -1
};
console.time('vm-normal');
vm.createContext(sandbox);
for (let i = 0 ; i < 100000 ; i++) {
vm.runInContext(`current = ${i};`, sandbox, {
displayErrors: false
});
}
console.timeEnd('vm-normal');
'use strict';
const
vm = require('vm'),
sandbox = {
current: -1
};
console.time('vm-with-timeout');
vm.createContext(sandbox);
for (let i = 0 ; i < 100000 ; i++) {
vm.runInContext(`current = ${i};`, sandbox, {
displayErrors: false,
timeout: 1000
});
}
console.timeEnd('vm-with-timeout');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment