Skip to content

Instantly share code, notes, and snippets.

@Artur-
Last active August 29, 2015 14:22
Show Gist options
  • Save Artur-/abac860b9e6e80b3bf29 to your computer and use it in GitHub Desktop.
Save Artur-/abac860b9e6e80b3bf29 to your computer and use it in GitHub Desktop.
Measure todomvc selectall
var toggleAll=document.querySelector("#toggle-all");
var allCheckboxes = document.querySelectorAll("ul input[type=checkbox]");
var firstCheckbox = allCheckboxes[0];
var lastCheckbox = allCheckboxes[allCheckboxes.length-1];
waitFor = !toggleAll.checked;
console.log("Wait until "+waitFor);
var startTime = new Date();
toggleAll.click();
var endTime = new Date();
if (firstCheckbox.checked == waitFor) {
console.log("Done synchronously in "+(endTime-startTime)+"ms");
alert("Took "+(endTime-startTime)+"ms");
} else {
console.log("Synchronous part done in "+(endTime-startTime)+"ms. Waiting for async part");
var timer = setInterval(function() {
if (firstCheckbox.checked == waitFor) {
endTime = new Date();
window.alert("Took "+(endTime-startTime)+"ms (async)");
console.log("Done asynchronously in "+(endTime-startTime)+"ms");
clearInterval(timer);
} else {
console.log("Still waiting");
}
},1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment