HTML Preparation code:
AخA
 
1
<div id="test-subject" data-test="foo"></div>
Tests:
  • Shorthand

     
    function attr(element, attribute, value) {
        if (value) {
            element.setAttribute(attribute, value);
            return;
        }
        return element.getAttribute(attribute);
    }
    var test_subject = document.getElementById("test-subject");
    var i = 1000;
    while (i--) {
        attr(test_subject, 'data-test', i);
        test_subject.innerHTML = attr(test_subject, 'data-test');
    }
  • Native

     
    var test_subject = document.getElementById("test-subject");
    var i = 1000;
    while (i--) {
        test_subject.setAttribute('data-test', i);
        test_subject.innerHTML = test_subject.getAttribute('data-test');
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Shorthand
    Native

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4042.0 Safari/537.36
Chrome 81 on Windows
View result in a separate tab
Test name Executions per second
Shorthand 17.4 Ops/sec
Native 16.8 Ops/sec