var maximumLoop = 100000;
function runLoop() {
const t0 = performance.now();
let targetElement = document.getElementById('runResult');
if (targetElement) {
// reset result before start.
targetElement.innerHTML = '';
}
for (i = 1; i <= maximumLoop; i++) {
if (targetElement) {
targetElement.insertAdjacentHTML('beforeend', i + ', ');
}
if (i%100 == 0) {
if (targetElement) {
targetElement.insertAdjacentHTML('beforeend', '<br>' + "\n");
}
}
}// endfor;
const t1 = performance.now();
// https://developer.mozilla.org/en-US/docs/Web/API/Performance/now benchmark time original source code.
console.log(`Call to this function took ${t1 - t0} milliseconds.`);
}
function runLoop2(event) {
if (event.target.classList.contains('runLoop')) {
const t0 = performance.now();
let targetElement = document.getElementById('runResult');
if (targetElement) {
// reset result before start.
targetElement.innerHTML = '';
}
for (i = 1; i <= maximumLoop; i++) {
if (targetElement) {
targetElement.insertAdjacentHTML('beforeend', i + ', ');
}
if (i%100 == 0) {
if (targetElement) {
targetElement.insertAdjacentHTML('beforeend', '<br>' + "\n");
}
}
}// endfor;
const t1 = performance.now();
// https://developer.mozilla.org/en-US/docs/Web/API/Performance/now benchmark time original source code.
console.log(`Call to this function took ${t1 - t0} milliseconds.`);
}
}
function listenEventDelegation() {
document.addEventListener('click', function(event) {
if (event.target.classList.contains('runLoop')) {
runLoop();
}
});
}