Skip to content

Instantly share code, notes, and snippets.

@gdborton
Last active November 15, 2017 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdborton/c6a8ce4532d12e2198ed1987bfe39097 to your computer and use it in GitHub Desktop.
Save gdborton/c6a8ce4532d12e2198ed1987bfe39097 to your computer and use it in GitHub Desktop.
Script used to compare acorn.parse on source vs JSON.parse on existing ASTs
const fs = require('fs');
const glob = require('glob');
const acorn = require('acorn-dynamic-import').default;
const sourceFiles = glob.sync('../location/*.source.json');
const astFiles = glob.sync('../location/*.ast.json');
const filesToParse = sourceFiles.map(fileLocation => {
return JSON.parse(fs.readFileSync(fileLocation, 'utf8'));
});
console.log('found', filesToParse.length, ' source files to parse');
console.time('parsing all the files');
filesToParse.forEach((thing) => {
acorn.parse(thing.source, thing.parseOptions);
});
console.timeEnd('parsing all the files');
const astContents = astFiles.map((astFileLocation) => {
return fs.readFileSync(astFileLocation, 'utf8');
});
console.log('found', astContents.length, ' ast files to parse');
console.time('json parsing asts');
astContents.forEach((astString) => {
return JSON.parse(astString);
});
console.timeEnd('json parsing asts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment