setAttribute vs obj.className (v2)

Revision 2 of this benchmark created by Gildas on


Preparation HTML

<div id="testing"></div>
<script>
  function set_class_a(obj, class_name) {
   obj.setAttribute('class', class_name);
  };
  
  function set_class_b(obj, class_name) {
   obj.className = class_name;
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
setAttribute();
set_class_a(document.getElementById('testing'), 'testing');
ready
obj.className
set_class_b(document.getElementById('testing'), 'testing');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Carl Danley on
  • Revision 2: published by Gildas on