sdfgw4g4es

JavaScript performance comparison

Test case created by Carson Kahn

Preparation code

<div id='fizzle' class='classname'>

  
  <script type='text/css' id='thisone'>
       h1   {   color: green}
  </script>
  <h1>asdfasdfasfd</h1>
</div>

<div id='yaay' class='wheep'>

  
  <script type='text/css'>
       h1   {   color: blue}
  </script>
  <h1>asdfasdfasfd</h1>
</div>

  <h1>asdfasdfasfd</h1>

<p id='#bb'>wertwert23452354234</p>



zzzzzzz


<script src='scoped.js'>

// if you use very many templates, consider adding async attr so they don't block the parser (it wouldn't make too much diff, but still)

// if you call somewhere with document.resolveScopes()('somefunctionbody')()

//alert(_options) // …this callback fires first
// someFunctionBody() // …this invisibly fires second

</script>

    

Preparation code output

<div id='fizzle' class='classname'> <h1>asdfasdfasfd</h1> </div> <div id='yaay' class='wheep'> <script type='text/css'> h1 { color: blue} </script> <h1>asdfasdfasfd</h1> </div> <h1>asdfasdfasfd</h1> <p id='#bb'>wertwert23452354234</p> zzzzzzz <script src='scoped.js'> // if you use very many templates, consider adding async attr so they don't block the parser (it wouldn't make too much diff, but still) // if you call somewhere with document.resolveScopes()('somefunctionbody')() //alert(_options) // …this callback fires first // someFunctionBody() // …this invisibly fires second </script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
bins
    var parseScopedCSS = function (op, final) {

        for (
           var root = op.id && doc.getElementById(op.id) || op.root || doc.body,
               caches = root.getElementsByTagName(op.bins || 'script'),
               scopes_ = [], _each,
               i = 0;
           _each = caches[i++];
           '' == _each.src && (op.type && op.type.toLowerCase() || 'text/css') == _each.type.toLowerCase()
           && scopes_.push(_each)
        );

        for (
           var head  = doc.head || doc.getElementsByTagName('head')[0],
               style = doc.createElement('style'),
               styleStr = '', scope, scopeID,
               n = 0, Done;
           _each = scopes_[n++] || (style.styleSheet? style.styleSheet.cssText += styleStr :style.appendChild(doc.createTextNode(styleStr)), head.appendChild(style) && Done);
           styleStr += _each.firstChild.nodeValue.replace(/((?:^|\})\s*)([^\d\s\{\};@]+[^\{\};@]*\{)(\s*(?:(?:\S[^\}])|;|\}))/g,             '$1 ' + scopeID + ' $2$3')
                                                 .replace(/(\s*@\w{2,}\s*\([^\}\)]*\)\s*\{\s)\s*([^\d\s\{\};@]+[^\{\};@]*\{)(\s*[^\}]\})*/g, '$1 ' + scopeID + ' $2$3')
                                                 .replace(/(?:(?:#\w+)|(?:\.\w{6,}))\s+(body?)|(html?)/gi, '$1'), scope.className += ' '+(op.litmus || 'scoped')+' ' + scopeID.substring(1)
        ) scope = _each.parentNode, scopeID = scope.id != ''? '#'+scope.id :'.scope'+-745832*~i;

        var scripts_ = 'script' != op.bins && op.bins || root != doc.body && doc.documentElement != root? doc.body.getElementsByTagName('script') :caches,
            goto = scripts_[scripts_.length-1];
          !!goto.src && Function('_scopes', '_options', goto.firstChild.nodeValue).call(this, scopes_, op.devObj != win? JSON.stringify(op) :op);

        final && final();

    };
pending…
no bins
    var parseScopedCSS = function (op, final) {

        for (
           var root = op.id && doc.getElementById(op.id) || op.root || doc.body,
               caches = root.getElementsByTagName('script'),
               scopes_ = [], _each,
               i = 0;
           _each = caches[i++];
           '' == _each.src && (op.type && op.type.toLowerCase() || 'text/css') == _each.type.toLowerCase()
           && scopes_.push(_each)
        );

        for (
           var head  = doc.head || doc.getElementsByTagName('head')[0],
               style = doc.createElement('style'),
               styleStr = '', scope, scopeID,
               n = 0, Done;
           _each = scopes_[n++] || (style.styleSheet? style.styleSheet.cssText += styleStr :style.appendChild(doc.createTextNode(styleStr)), head.appendChild(style) && Done);
           styleStr += _each.firstChild.nodeValue.replace(/((?:^|\})\s*)([^\d\s\{\};@]+[^\{\};@]*\{)(\s*(?:(?:\S[^\}])|;|\}))/g,             '$1 ' + scopeID + ' $2$3')
                                                 .replace(/(\s*@\w{2,}\s*\([^\}\)]*\)\s*\{\s)\s*([^\d\s\{\};@]+[^\{\};@]*\{)(\s*[^\}]\})*/g, '$1 ' + scopeID + ' $2$3')
                                                 .replace(/(?:(?:#\w+)|(?:\.\w{6,}))\s+(body?)|(html?)/gi, '$1'), scope.className += ' '+(op.litmus || 'scoped')+' ' + scopeID.substring(1)
        ) scope = _each.parentNode, scopeID = scope.id != ''? '#'+scope.id :'.scope'+-745832*~i;

        var scripts_ = root != doc.body && doc.documentElement != root? doc.body.getElementsByTagName('script') :caches,
            goto = scripts_[scripts_.length-1];
          !!goto.src && Function('_scopes', '_options', goto.firstChild.nodeValue).call(this, scopes_, op.devObj != win? JSON.stringify(op) :op);

        final && final();

    };
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 Comments

asdfasdfasfd

asdfasdfasfd

asdfasdfasfd

wertwert23452354234

zzzzzzz