remove attribute vs set to false

Benchmark created by Dan Manastireanu on


Description

For cases in which you want an attribute that works like a flag.

Preparation HTML

<input id="input" type="text" value="The quick brown fox jumps over the lazy dog" attr="true">
<script>
  var input = document.getElementById('input'),
      test = function(i) {
    if (i.getAttribute('attr') == true) {
     throw 'This test should fail:' + i.getAttribute('attr');
    }
      };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
remove attribute
input.removeAttribute('attr');
test(input);
ready
set attribute to false
input.setAttribute('attr', false);
test(input);
ready

Revisions

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

  • Revision 1: published by Dan Manastireanu on
  • Revision 2: published by Spencer Drager on
  • Revision 3: published by Tim Tucker on
  • Revision 4: published by Tim Tucker on
  • Revision 5: published by Tim Tucker on