setSpecialCharectersAttribute (v9)

Revision 9 of this benchmark created by Sander Elias on


Setup

var div = document.createElement('div');
    var templateDiv = document.createElement('div');
    var key = 'key';
    var value = '"constant"';
    var QUOT = /"/g;
    var attrCache = [];
    
    function specialSet(el, attr, value) {
      attr = '[' + attr + ']';
      if (!attrCache[attr]) {
        templateDiv.innerHTML = '<div ' + attr + '="">';
        attrCache[attr] = templateDiv.firstChild.attributes[0].cloneNode();
      }
      attrCache[attr] = value;
      el.attributes.setNamedItem(attrCache[attr])
    }

Test runner

Ready to run.

Testing in
TestOps/sec
setAttribute
div.setAttribute('bind-' + key, value);
ready
setSpecialAttribute
specialSet(div, key, value)
ready

Revisions

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

  • Revision 1: published by Misko Hevery on
  • Revision 2: published on
  • Revision 3: published on
  • Revision 5: published by Sander Elias on
  • Revision 6: published by Sander Elias on
  • Revision 7: published by Sander Elias on
  • Revision 9: published by Sander Elias on