Skip to content

Instantly share code, notes, and snippets.

@akanshgulati
Last active June 9, 2019 19:21
Show Gist options
  • Save akanshgulati/75a031c33878f97c0008b781184506c3 to your computer and use it in GitHub Desktop.
Save akanshgulati/75a031c33878f97c0008b781184506c3 to your computer and use it in GitHub Desktop.
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