Skip to content

Instantly share code, notes, and snippets.

@mikeal
Created January 22, 2011 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikeal/791539 to your computer and use it in GitHub Desktop.
Save mikeal/791539 to your computer and use it in GitHub Desktop.
var one = 'http://blah'
, two = '/asdf/asdf/af'
;
function regexTest () {
var start = new Date();
var i = 0;
while (i<1000000) {
if ( !/^http?:/.test(one) ) true
if ( !/^http?:/.test(two) ) true
i++;
}
var end = new Date();
console.log('regexTest: '+(end - start))
}
function sliceTest () {
var start = new Date();
var i = 0;
while (i<1000000) {
if (one.slice(0, 'http'.length) === 'http') true
if (two.slice(0, 'http'.length) === 'http') true
i++
}
var end = new Date();
console.log('sliceTest: '+(end - start))
}
regexTest();
sliceTest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment