Skip to content

Instantly share code, notes, and snippets.

@jneen
Last active January 2, 2016 18:19
Show Gist options
  • Save jneen/8342566 to your computer and use it in GitHub Desktop.
Save jneen/8342566 to your computer and use it in GitHub Desktop.
> time node ~/tmp/perf-test.js
dynamic
real 0m0.697s
user 0m0.690s
sys 0m0.013s
> time node ~/tmp/perf-test.js static
static
real 0m0.680s
user 0m0.670s
sys 0m0.013s
#!/usr/bin/env node
function fixRegex(re) {
var source = re.source;
var flags = (''+re).slice(source.length+2);
return new RegExp("^(?:"+source+")", flags);
}
if (process.argv[2] === 'static') {
console.log('static');
function re() { return /^a+/; }
}
else {
console.log('dynamic');
function re() { return fixRegex(/a+/); }
}
var testStr = 'aaaaaaa'
for (var i = 0; i < 1000000; i += 1) {
re().exec(testStr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment