Script Preparation code:
AخA
 
var placeHolderElem = document.createElement('div');
placeHolderElem.id = "PlaceHolder";
document.body.append(placeHolderElem);
var placeHolder = document.querySelector('#PlaceHolder');
var isEnabled = true;
var itemList = [1, 2, 3, 4];
Tests:
  • Template String

     
    const subTemplate = (item) => `<li>${item}</li>`;
    const template = `<div class="container">
        ${isEnabled ? 'Enabled' : 'Disabled'}
        <ul>${itemList.map(subTemplate).join('')}</ul>
    </div>`;
    placeHolder.innerHTML = template;
  • Template Function

    x
     
    const templateFunction = function (obj) {
        obj || (obj = {});
        var __t, __p = '', __j = Array.prototype.join;
        function print() { __p += __j.call(arguments, '') }
        with (obj) {
            __p += '<div class="container">\r\n    ' +
                ((__t = (isEnabled ? 'Enabled' : 'Disabled')) == null ? '' : __t) +
                '\r\n    <ul>\r\n        ';
            itemList.forEach((item) => {
                ;
                __p += '\r\n        <li>' +
                    ((__t = (item)) == null ? '' : __t) +
                    '</li>\r\n        ';
            });
            __p += '\r\n    </ul>\r\n</div>';
        }
        return __p;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Template String
    Template Function

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Chrome 104 on Windows
View result in a separate tab
Test name Executions per second
Template String 54452.6 Ops/sec
Template Function 815799808.0 Ops/sec