Last active
May 6, 2020 00:22
-
-
Save robmcl4/080bf388c95de3b2761307b39d6f895a to your computer and use it in GitHub Desktop.
This file contains 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 parse = require('@babel/parser').parse; | |
const traverse = require('@babel/traverse').default; | |
for (let i=1; i<13; i++) { | |
const multiple = Math.pow(2, i); | |
const toParse = '[' + Array(multiple).fill('100').join(',') + ']'; | |
if (i == 0) { | |
// warm up a bit | |
const ast = parse(toParse); | |
for (let j=0; j<1000; j++) { | |
traverse(ast, {enter: () => {}}); | |
} | |
} | |
const ast = parse(toParse); | |
let elapse = 0; | |
for (let j=0; j<1000; j++) { | |
const begin = +(new Date()); | |
traverse(ast, {enter: () => {}}); | |
elapse += (+new Date()) - begin; | |
} | |
console.log(`${multiple},${elapse / 1000}`); | |
} | |
/* output: */ | |
/* | |
2,0.043 | |
4,0.033 | |
8,0.017 | |
16,0.014 | |
32,0.022 | |
64,0.041 | |
128,0.088 | |
256,0.236 | |
512,0.729 | |
1024,2.545 | |
2048,10.699 | |
4096,43.111 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment