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 (v9) Revision 9 of this benchmark created on June 11, 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 = 'baz' ;
function addClass_className (el, className ) {
el.className += " " + className;
}
function removeClass_className (ele, cls ) {
var reg = new RegExp ('(\\s|^)' + cls + '(\\s|$)' );
ele.className = ele.className .replace (reg, ' ' ).replace (/^\s\s*/ , '' ).replace (/\s\s*$/ , '' );
}
Teardown
node.className = '' ;
Test runner Ready to run.
Run Quick Run Testing in Test Ops/sec classList (add) node.className = '' ;
node.classList .add ('foo' );
node.classList .add ('bar' );
node.classList .add ('baz' );
node.classList .add ('kar' );
ready
One by one node.className = '' ;
node.className += ' foo' ;
node.className += ' bar' ;
node.className += ' baz' ;
node.className += ' kar' ;
ready
className raw node.className = '' ;
node.className = 'foo bar baz kar' ;
ready
Store node classList node.className = '' ;
var cl = node.classList ;
cl.add ('foo' );
cl.add ('bar' );
cl.add ('baz' );
cl.add ('kar' );
ready
Bound function node.className = '' ;
var nodeClAdd = node.classList .add .bind (node.classList );
nodeClAdd ('foo' );
nodeClAdd ('bar' );
nodeClAdd ('baz' );
nodeClAdd ('kar' );
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