Skip to content

Instantly share code, notes, and snippets.

@andry1
Created August 25, 2011 16:31
Show Gist options
  • Save andry1/1171091 to your computer and use it in GitHub Desktop.
Save andry1/1171091 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
r = new RegExp("^(\w+)\s+")
str = "abc 123"
console.log("testing new RegExp(...) [non-compiled]")
start = Date.now()
for(i = 0; i < 10000000; ++i) {
str.match(r)
}
end=Date.now()
console.log("..."+(end-start)+"ms")
console.log("testing new RegExp(...) [compiled]")
r.compile()
start = Date.now()
for(i = 0; i < 10000000; ++i) {
str.match(r)
}
end=Date.now()
console.log("..."+(end-start)+"ms")
console.log("testing str.match(/.../)")
start = Date.now()
for(i = 0; i < 10000000; ++i) {
str.match(/^(\w+)\s+/)
}
end=Date.now()
console.log("..."+(end-start)+"ms")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment