A benchmark of different methods to empty an HTML element
Senior Developer, Designer, Technologist! 🇮🇷
Search for a command to run...
Senior Developer, Designer, Technologist! 🇮🇷
No comments yet. Be the first to comment.
Here are the steps I used to to upgrade MySQL to MariaDB in XAMPP on Windows in about 5 minutes. After completing this process, MariaDB will look and work just like MySQL. You may even notice a performance increase in your website. No need to panic f...
TL;DR: Three spammy “free money” issues mentioned my username. GitHub removed the issues, but a phantom notification stuck around: the badge count wouldn’t clear and the notifications list was empty. I contacted GitHub Support, learned why this can h...
Links Cheat Sheet Production usage Persistence JSON JSON DataType RedisJSON @ GitHub Installing Redis on Windows Memurai: Redis for Windows Installing curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-arch...
# Secrets [Ss]ecret.* *.sql *.env *.env.* !*.env.template !*.env.*.template *.local # Setup samples !/setup # Temps **/[Tt]emp **/[Tt]emps **/.DS_Store **/._.DS_Store vite.config.*.timestamp-* *.log yarn-error.log # Packages node_modules node_modu...
Linux Users In Linux, users are defined in the /etc/passwd file, and their passwords are stored in the /etc/shadow file. [!NOTE] Note At one time, this file stored the hashed passwords of every user on the system. However, this responsibility has be...
function empty(element) {
if (element.innerHTML) {
element.innerHTML = "";
}
}
function empty1(element) {
element.innerHTML = "";
}
function empty2(element) {
while (element.firstChild) {
element.removeChild(element.firstChild);
}
}
function empty3(element) {
var child = element.firstChild;
while (child) {
element.removeChild(child);
child = element.firstChild;
}
}
function empty4(element) {
var children = element.childNodes;
for (var i = 0; i < children.length; i++) {
element.removeChild(children[i]);
}
}
function empty5(element) {
var children = element.getElementsByTagName("*");
for (var i = 0; i < children.length; i++) {
element.removeChild(children[i]);
}
}
function empty6(element) {
var children = element.children;
for (var i = 0; i < children.length; i++) {
element.removeChild(children[i]);
}
}
function empty7(element) {
while (element.firstChild) {
element.removeChild(element.firstChild);
}
while (element.lastChild) {
element.removeChild(element.lastChild);
}
}
// Benchmark the functions
function benchmark(functionName) {
var start = performance.now();
for (var i = 0; i < 1000; i++) {
var element = document.createElement("div");
for (var k = 0; k < 1000; k++) {
var child = document.createElement("div");
element.appendChild(child);
}
functionName(element);
}
var end = performance.now();
return end - start;
}
// console.log(benchmark("jQuery $(element).empty"));
console.log("empty", benchmark(empty));
console.log("empty1", benchmark(empty1));
console.log("empty2", benchmark(empty2));
console.log("empty3", benchmark(empty3));
console.log("empty4", benchmark(empty4));
console.log("empty5", benchmark(empty5));
console.log("empty6", benchmark(empty6));
console.log("empty7", benchmark(empty7));