Js css benchmark

JavaScript performance comparison

Test case created by jl9404

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    function addStyle1(sStyle) {
      if (!this.jStyle) this.jStyle = $('<style id="an-style" type="text/css"></style>').appendTo('head');
      this.jStyle[0].styleSheet ? this.jStyle[0].styleSheet.cssText += sStyle : this.jStyle.append(sStyle);
    }
   
   
    function addStyle2(newcss) {
      if ('\v' == 'v') /* ie only */
      {
        document.createStyleSheet().cssText = newcss;
      } else {
        var tag = document.createElement('style');
        tag.type = 'text/css';
        document.getElementsByTagName('head')[0].appendChild(tag);
        tag[(typeof document.body.style.WebkitAppearance == 'string') /* webkit only */ ? 'innerText' : 'innerHTML'] = newcss;
      }
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
addStyle1
addStyle1('.abc {font-weight:bold}');
pending…
addStyle2
addStyle2('.abc {font-weight:bold}');
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

Add a comment