Cost of Polymorphism (v10)

Revision 10 of this benchmark created on


Description

https://bugs.chromium.org/p/chromium/issues/detail?id=1413961

Setup

const tags = ["a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dir", "div", "dl", "dt", "element", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "isindex", "kbd", "keygen", "label", "legend", "li", "link", "listing", "main", "map", "mark", "marquee", "menu", "menuitem", "meta", "meter", "nav", "nobr", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "plaintext", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "shadow", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp"];
const elementCount = tags.length;
for(let i=0; i<elementCount; i++) {
  // prime the creation of elements before the test
 document.createElement(tags[i]);
}
const divIndex = tags.indexOf('div');
const setAttribute = HTMLElement.prototype.setAttribute;

Test runner

Ready to run.

Testing in
TestOps/sec
Create All elements as DIVs and set ID
for(let i=0; i<elementCount; i++) {
  document.
     createElement(tags[divIndex]).
     setAttribute('id', 'value');
}
ready
Create all elements as different types and set ID
for(let i=0; i<elementCount; i++) {
  document.
     createElement(tags[i]).
     setAttribute('id', 'value');
}
ready
Create all elements as different types and set ID through monomorphic call
for(let i=0; i<elementCount; i++) {
  setAttribute.call(
    document.
      createElement(tags[i]), 
    'id', 
    'value'
  );
}
ready

Revisions

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