Skip to content

Instantly share code, notes, and snippets.

@DracoBlue
Forked from mikeal/gist:791539
Created January 22, 2011 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DracoBlue/791545 to your computer and use it in GitHub Desktop.
Save DracoBlue/791545 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))
}
function indexOfTest () {
var start = new Date();
var i = 0;
while (i<1000000) {
if ('http'.indexOf(one) === 0) true
if ('http'.indexOf(two) === 0) true
i++
}
var end = new Date();
console.log('indexOfTest: '+(end - start))
}
regexTest();
sliceTest();
indexOfTest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment