Last active
January 2, 2016 18:19
-
-
Save jneen/8342566 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
> 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 |
This file contains hidden or 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
#!/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