Skip to content

Instantly share code, notes, and snippets.

@axemclion
Last active February 11, 2016 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axemclion/4eeb743fb91302d03210 to your computer and use it in GitHub Desktop.
Save axemclion/4eeb743fb91302d03210 to your computer and use it in GitHub Desktop.
Latency Performance calculations for React-Worker-DOM
var start, results = [];
var ITERATIONS = 100;
var addButton = document.querySelectorAll('.btn.btn-primary')[0];
var addItem = function() {
if (results.length < ITERATIONS) {
start = performance.now();
addButton.click();
} else {
console.log('Testing done, average is %s milliseconds, all data is', results.reduce(function(a, b) {
return a + b;
}, 0) / results.length);
}
}
addItem(); // set the first item
window.setTimeout(function() {
var list = document.getElementsByTagName('ol')[0];
new MutationObserver(function(mutations) {
results.push(performance.now() - start);
window.setTimeout(addItem, 100);
}).observe(list, {
childList: true
});
addItem();
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment