Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
average response time by domain
;(function(domains)
{
var entries = window.performance.getEntries();
var result = {
total: 0,
count: 0,
domains: {}
};
for (var entry = 0; entry < entries.length; entry++)
{
var split = entries[entry].name.split("://");
var resourceName = split[split.length - 1];
for (var domain = 0; domain < domains.length; domain++)
{
if (resourceName.indexOf(domains[domain]) === 0)
{
result.count++;
result.total += entries[entry].duration;
result.domains[domains[domain]] = result.domains[domains[domain]] ||
{
total: 0,
count: 0
};
result.domains[domains[domain]].count++;
result.domains[domains[domain]].total += entries[entry].duration;
}
}
}
function calcAverage(o)
{
o.average = o.total / o.count;
}
calcAverage(result);
console.log("average:" + result.average);
for (var domainName in result.domains)
{
calcAverage(result.domains[domainName]);
console.log(domainName + ":" + result.domains[domainName].average);
}
})(["www.soasta.com", "platform.twitter.com"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment