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 className VS classList Showdown (v18) Revision 18 of this benchmark created by Andrey Sklyarevskiy on December 8, 2014 Description How much faster is classList.add/remove than className regex manipulation?
Preparation HTML <style type ="text/css" >
.foo { color:#F00; height:100px; opacity:0.3; } .bar { color:#0F0; height:200px;
opacity:0.5; } .baz { color:#00F; height:300px; opacity:0.7; }
</style >
<div id ="base" class ="foo bar" >
<div class ="foo bar baz" >
test 1
</div >
<span class ="foo bar" >
test 2
</span >
<span class ="baz" >
test 3
</span >
</div >
Setup var node = document .getElementById ('base' ),
className = node.className ;
function addClass_className (el, className ) {
if (el.className .indexOf (className) == -1 ) {
el.className += " " + className;
}
}
function addClass_className2 (el, className ) {
el.className = [el.className , className].join (' ' );
}
function removeClass_className (ele, cls ) {
var reg = new RegExp ('\\b' + cls + '\\b' );
ele.className = ele.className .replace (reg, '' )
}
Test runner Ready to run.
Run Quick Run Testing in Test Ops/sec classList (add) var classList = node.classList ;
classList.add ('foo' );
classList.add ('bar' );
classList.add ('baz' );
node.className =className;
ready
className (add) walkontable 0.2.0 addClass_className (node, 'foo' );
addClass_className (node, 'bar' );
addClass_className (node, 'baz' );
node.className =className;
ready
className2 (add) addClass_className2 (node, 'foo' );
addClass_className2 (node, 'bar' );
addClass_className2 (node, 'baz' );
node.className =className;
ready
Revisions You can edit these tests or add more tests to this page by appending /edit to the URL.
Revision 1 : published by Jason Miller on October 12, 2012 Revision 2 : published on October 14, 2012 Revision 3 : published by Jason Miller on February 16, 2013 Revision 5 : published by Marcin on March 25, 2013 Revision 6 : published on April 25, 2013 Revision 7 : published on May 2, 2014 Revision 8 : published on May 16, 2014 Revision 9 : published on June 11, 2014 Revision 11 : published on August 31, 2014 Revision 12 : published on September 25, 2014 Revision 13 : published on September 25, 2014 Revision 14 : published by Bezon on December 5, 2014 Revision 15 : published by Bezon on December 6, 2014 Revision 16 : published by Andrey Sklyarevskiy on December 6, 2014 Revision 17 : published by Bezon on December 8, 2014 Revision 18 : published by Andrey Sklyarevskiy on December 8, 2014 Revision 19 : published on January 4, 2015 Revision 20 : published by Mike Haverstock on May 22, 2015 Revision 21 : published on May 22, 2015 Revision 22 : published on May 22, 2015 Revision 23 : published on May 22, 2015 Revision 24 : published on May 22, 2015 Revision 25 : published on September 12, 2015 Revision 26 : published on November 4, 2015