JSFiddle - React, Tailwind, and code Playground

for CSCI E3, Harvard University author(s): Larry Bouthillier

by DustyWhite

HTML

WEEK 4: Lawrence's example from the Intro video on the comparison of two different functions:

<div id="zeroth">

</div>
<div id="first">

</div>
<div id="second">

</div>

JavaScript

//comparing performance of getElementByID() vs. querySelector()

console.log("by ID");
let d = new Date();
for (let i=0; i<100000; i++){
	document.getElementById("first");
}
console.log(new Date().getTime() - d.getTime());


console.log("now query selector");
d = new Date();
for (let i=0; i<100000; i++){
	document.querySelector("#first");
}
console.log(new Date().getTime() - d.getTime());