<commit_before>const fs = require('fs')
const dsl = require('./dsl')
const vm = require('vm')

module.exports = function (file) {
  return vm.runInNewContext(
    fs.readFileSync(file, 'utf8'),
    Object.assign({ module, require }, global, dsl),
    { filename: file }
  )
}<commit_msg>Reuse VM context for performance<commit_after>const fs = require('fs')
const dsl = require('./dsl')
const vm = require('vm')

const sandbox = Object.assign({ module, require }, global, dsl)
vm.createContext(sandbox, { name: 'PureSpec' })

module.exports = function (file) {
  return vm.runInContext(
    fs.readFileSync(file, 'utf8'),
    sandbox,
    { filename: file }
  )
}
{'fraction_non_alphanumeric': 0.15987933634992457, 'fraction_numerical': 0.0030165912518853697, 'mean_word_length': 4.26984126984127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2698150', 'n_tokens_mistral': 223, 'n_tokens_neox': 220, 'n_words': 56}