Js css benchmark
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
addStyle1 |
|
pending… |
addStyle2 |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments