JSFiddle - React, Tailwind, and code Playground
HTML
<div></div>
<form></form>
<span id="log"></span>
<input type="button" id="fast" value="fast" />
<input type="button" id="slow" value="slow" />
JavaScript
function randomString(length) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
if (! length) {
length = Math.floor(Math.random() * chars.length);
}
var str = '';
for (var i = 0; i < length; i++) {
str += chars[Math.floor(Math.random() * chars.length)];
}
return str;
}
function log(msg) {
const elem = document.getElementById("log");
elem.innerHTML += msg;
}
function addSelect(target) {
log("Insert into " + target);
var html = target + "<select>";
for(var i = 0; i < 10000; i++) {
html += "<option value='" + i + "'>" + randomString(30) + "</option>";
}
html += "</select>";
const start = new Date();
document.getElementsByTagName(target)[0].innerHTML = html;
const end = new Date();
log(" takes " + (end - start) + "ms<br>");
}
document.getElementById("fast").onclick= function() {addSelect('div')};
document.getElementById("slow").onclick= function() {addSelect('form')};