jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase .
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2 Can be accessed at:
https://jsperf.app/negative-modulo/2 style vs cssText vs setAttribute Benchmark created by rmaksim on November 18, 2012 Preparation HTML <script src ="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" > </script >
<style >
#test div {
float:left;
}
</style >
<div id ="test" > </div >
Setup var $test = $("#test" )
, cssText = typeof (document .createElement ("div" ).style .cssText ) != "undefined"
, elems = []
, colors = "#f88 #8f8 #88f #ff8 #8ff #f8f" .split (" " )
, el
, text
, count = 0
test.innerHTML = ""
for (var i=0 ; i<100 ; i++) {
var el = $("<div>" )
elems.push (el)
$test.append (el)
}
Test runner Ready to run.
Run Quick Run Testing in Test Ops/sec style for (var i=0 ; i<100 ; i++) {
el = elems[i][0 ]
el.style .width = (i%10 )+"px"
el.style .height = (i%10 )+"px"
el.style .background = colors[++count%colors.length ]
}
ready
cssText if (!cssText) {
Benchmark .abort ()
}
for (var i=0 ; i<100 ; i++) {
el = elems[i][0 ]
text = 'width:' +(i%10 )+'px;'
+ 'height:' +(i%10 )+'px;'
+ 'background:' +colors[++count%colors.length ]
el.style .cssText = text
}
ready
setAttribute for (var i=0 ; i<100 ; i++) {
el = elems[i][0 ]
text = 'width:' +(i%10 )+'px;'
+ 'height:' +(i%10 )+'px;'
+ 'background:' +colors[++count%colors.length ]
el.setAttribute ("style" , text)
}
ready
jQuery.css for (var i=0 ; i<100 ; i++) {
elems[i].css ({ width : i%10
, height : i%10
, background : colors[++count%colors.length ]
})
}
ready
Revisions You can edit these tests or add more tests to this page by appending /edit to the URL.
Revision 1 : published by rmaksim on November 18, 2012 Revision 2 : published on November 18, 2012 Revision 3 : published by Rei on November 18, 2012 Revision 5 : published on November 19, 2012 Revision 8 : published on January 17, 2014 Revision 9 : published on March 3, 2014 Revision 10 : published on July 23, 2014 Revision 11 : published on August 13, 2014 Revision 12 : published on January 5, 2015 Revision 13 : published by Oleg on February 7, 2015