Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to extract perf results from KeyCDN
// Calculates the average of TTFB from various locations of the
// KeyCDN server using its performance tool - https://tools.keycdn.com/performance
// Paste this script in the console after getting the performance test of a url
(function () {
const TTFBIndex = 8
// Get all the rows of the performance table and remove the first heading row from it;
const rows = Array.from(document.querySelector(`#perfResult`).children[1].tBodies[0].children).slice(1);
// calculating sum of the values
const sum = rows.reduce((acc, row) => {
var text = row.children[TTFBIndex].innerText;
if (text.indexOf(`ms`) > -1) {
acc += parseFloat(text);
} else if (text.indexOf(`s`) > -1) {
acc += parseFloat(text);
}
return acc
}, 0)
console.log(`Average `, sum / rows.length);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment