Skip to content

Instantly share code, notes, and snippets.

@mikeal
Created January 22, 2011 22:02
Show Gist options
  • Select an option

  • Save mikeal/791539 to your computer and use it in GitHub Desktop.

Select an option

Save mikeal/791539 to your computer and use it in GitHub Desktop.

Revisions

  1. mikeal created this gist Jan 22, 2011.
    30 changes: 30 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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();